Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PoroCYon
pimpmobile
Commits
b43ab5f2
Commit
b43ab5f2
authored
May 21, 2009
by
Erik Faye-Lund
Browse files
update the gbfs-stdio bindings
Signed-off-by:
Erik Faye-Lund
<
kusmabite@gmail.com
>
parent
debe2aa4
Changes
2
Hide whitespace changes
Inline
Side-by-side
examples/gbfs_stdio.c
View file @
b43ab5f2
...
...
@@ -57,98 +57,98 @@ static const char *make_absolute_path(const char *path)
{
path
=
strchr
(
path
,
':'
)
+
1
;
}
/* no subdirectory-support. everything is in the root. */
if
(
path
[
0
]
==
'/'
)
path
++
;
return
path
;
}
static
int
gbfs_open_r
(
struct
_reent
*
r
,
void
*
fileStruct
,
const
char
*
path
,
int
flags
,
int
mode
)
static
int
gbfs_open_r
(
struct
_reent
*
r
,
void
*
fileStruct
,
const
char
*
path
,
int
flags
,
int
mode
)
{
struct
file_state
*
file
=
(
struct
file_state
*
)
fileStruct
;
/* we're a read-only file system */
if
((
flags
&
3
)
!=
O_RDONLY
)
{
r
->
_errno
=
EROFS
;
return
-
1
;
}
path
=
make_absolute_path
(
path
);
/* init file-data */
file
->
size
=
0
;
file
->
pos
=
0
;
file
->
data
=
gbfs_get_obj
(
file_system
,
path
,
&
file
->
size
);
/* check for failure */
if
(
NULL
==
file
->
data
)
return
-
1
;
return
(
int
)
file
;
}
static
int
gbfs_close_r
(
struct
_reent
*
r
,
int
fd
)
{
struct
file_state
*
file
=
(
struct
file_state
*
)
fd
;
/* nothing to be done */
return
0
;
}
static
in
t
gbfs_seek_r
(
struct
_reent
*
r
,
int
fd
,
in
t
pos
,
int
dir
)
static
off_
t
gbfs_seek_r
(
struct
_reent
*
r
,
int
fd
,
off_
t
pos
,
int
dir
)
{
int
position
;
struct
file_state
*
file
=
(
struct
file_state
*
)
fd
;
/* select origo */
switch
(
dir
)
{
case
SEEK_SET
:
position
=
pos
;
break
;
case
SEEK_CUR
:
position
=
file
->
pos
+
pos
;
break
;
case
SEEK_END
:
position
=
file
->
size
+
pos
;
break
;
default:
r
->
_errno
=
EINVAL
;
return
-
1
;
case
SEEK_SET
:
position
=
pos
;
break
;
case
SEEK_CUR
:
position
=
file
->
pos
+
pos
;
break
;
case
SEEK_END
:
position
=
file
->
size
+
pos
;
break
;
default:
r
->
_errno
=
EINVAL
;
return
-
1
;
}
/* check for seeks outside the file */
if
(
position
<
0
||
position
>
file
->
size
)
{
r
->
_errno
=
EINVAL
;
return
-
1
;
}
/* update state */
file
->
pos
=
position
;
return
file
->
pos
;
}
static
in
t
gbfs_read_r
(
struct
_reent
*
r
,
int
fd
,
char
*
ptr
,
in
t
len
)
static
ssize_
t
gbfs_read_r
(
struct
_reent
*
r
,
int
fd
,
char
*
ptr
,
size_
t
len
)
{
int
i
;
struct
file_state
*
file
=
(
struct
file_state
*
)
fd
;
/* clamp len to file-length */
if
(
len
+
file
->
pos
>
file
->
size
)
{
r
->
_errno
=
EOVERFLOW
;
len
=
file
->
size
-
file
->
pos
;
}
/* if we're already at the end of the file, there's nothing to copy */
if
(
file
->
pos
==
file
->
size
)
return
0
;
/* copy data */
for
(
i
=
0
;
i
<
len
;
++
i
)
{
...
...
@@ -156,7 +156,7 @@ static int gbfs_read_r(struct _reent *r,int fd,char *ptr,int len)
ASSERT
(
file
->
pos
>=
0
);
*
ptr
++
=
file
->
data
[
file
->
pos
++
];
}
return
i
;
}
...
...
@@ -172,25 +172,25 @@ static void gbfs_stat_file(struct file_state *file, struct stat *st)
st
->
st_size
=
file
->
size
;
st
->
st_blksize
=
1
;
/* we're not working on blocks, so one byte per block is all fine */
st
->
st_blocks
=
(
st
->
st_size
+
511
)
/
512
;
st
->
st_atime
=
0
;
/* 1970-01-01 00:00:00 FTW */
st
->
st_mtime
=
0
;
st
->
st_ctime
=
0
;
}
static
int
gbfs_fstat_r
(
struct
_reent
*
r
,
int
fd
,
struct
stat
*
st
)
static
int
gbfs_fstat_r
(
struct
_reent
*
r
,
int
fd
,
struct
stat
*
st
)
{
struct
file_state
*
file
=
(
struct
file_state
*
)
fd
;
gbfs_stat_file
(
file
,
st
);
}
static
int
gbfs_stat_r
(
struct
_reent
*
r
,
const
char
*
path
,
struct
stat
*
st
)
static
int
gbfs_stat_r
(
struct
_reent
*
r
,
const
char
*
path
,
struct
stat
*
st
)
{
struct
file_state
file
;
path
=
make_absolute_path
(
path
);
/* init file-data */
file
.
size
=
0
;
file
.
pos
=
0
;
...
...
@@ -201,23 +201,23 @@ static int gbfs_stat_r (struct _reent *r, const char *path, struct stat *st)
r
->
_errno
=
ENOENT
;
return
-
1
;
}
gbfs_stat_file
(
&
file
,
st
);
return
0
;
}
static
int
gbfs_chdir_r
(
struct
_reent
*
r
,
const
char
*
path
)
static
int
gbfs_chdir_r
(
struct
_reent
*
r
,
const
char
*
path
)
{
/* skip file system identifier, we only support one anyway */
path
=
make_absolute_path
(
path
);
/* no subdirs, so we'll only support the top level - ie empty string after stripping */
if
(
path
[
0
]
!=
'\0'
)
{
r
->
_errno
=
ENOTDIR
;
return
-
1
;
}
return
0
;
}
...
...
@@ -229,10 +229,10 @@ struct dir_state
static
DIR_ITER
*
gbfs_diropen_r
(
struct
_reent
*
r
,
DIR_ITER
*
dirState
,
const
char
*
path
)
{
struct
dir_state
*
dir
=
(
struct
dir_state
*
)
dirState
->
dirStruct
;
/* skip file system identifier, we only support one anyway */
path
=
make_absolute_path
(
path
);
/* the only supported path is the root of the file system. */
if
(
path
[
0
]
!=
'\0'
)
{
...
...
@@ -240,42 +240,42 @@ static DIR_ITER* gbfs_diropen_r(struct _reent *r, DIR_ITER *dirState, const char
else
r
->
_errno
=
ENOTDIR
;
return
NULL
;
}
/* reset file index */
dir
->
current_file
=
0
;
return
(
DIR_ITER
*
)
dir
;
}
static
int
gbfs_dirreset_r
(
struct
_reent
*
r
,
DIR_ITER
*
dirState
)
static
int
gbfs_dirreset_r
(
struct
_reent
*
r
,
DIR_ITER
*
dirState
)
{
struct
dir_state
*
dir
=
(
struct
dir_state
*
)
dirState
->
dirStruct
;
/* reset file index */
dir
->
current_file
=
0
;
return
0
;
}
static
int
gbfs_dirnext_r
(
struct
_reent
*
r
,
DIR_ITER
*
dirState
,
char
*
filename
,
struct
stat
*
filestat
)
static
int
gbfs_dirnext_r
(
struct
_reent
*
r
,
DIR_ITER
*
dirState
,
char
*
filename
,
struct
stat
*
filestat
)
{
struct
file_state
file
;
struct
dir_state
*
dir
=
(
struct
dir_state
*
)
dirState
->
dirStruct
;
/* init file-data */
file
.
size
=
0
;
file
.
pos
=
0
;
file
.
data
=
gbfs_get_nth_obj
(
file_system
,
dir
->
current_file
,
filename
,
&
file
.
size
);
/* check for failure (no more files) */
if
(
file
.
data
==
NULL
)
return
-
1
;
/* stat */
gbfs_stat_file
(
&
file
,
filestat
);
/* skip to next file */
dir
->
current_file
++
;
return
0
;
}
...
...
@@ -285,29 +285,31 @@ static int gbfs_dirclose_r (struct _reent *r, DIR_ITER *dirState)
}
static
devoptab_t
d
;
void
gbfs_init
(
int
set_default
)
int
gbfs_init
(
int
set_default
)
{
int
dev_id
;
file_system
=
find_first_gbfs_file
((
void
*
)
0x08000000
);
if
(
NULL
==
file_system
)
return
;
if
(
NULL
==
file_system
)
return
0
;
memset
(
&
d
,
0
,
sizeof
(
devoptab_t
));
d
.
name
=
"gbfs"
;
d
.
structSize
=
sizeof
(
struct
file_state
);
d
.
dirStateSize
=
sizeof
(
struct
dir_state
);
d
.
dirStateSize
=
sizeof
(
struct
dir_state
);
d
.
open_r
=
gbfs_open_r
;
d
.
close_r
=
gbfs_close_r
;
d
.
seek_r
=
gbfs_seek_r
;
d
.
read_r
=
gbfs_read_r
;
d
.
stat_r
=
gbfs_stat_r
;
d
.
fstat_r
=
gbfs_fstat_r
;
d
.
fstat_r
=
gbfs_fstat_r
;
d
.
chdir_r
=
gbfs_chdir_r
;
d
.
diropen_r
=
gbfs_diropen_r
;
d
.
dirreset_r
=
gbfs_dirreset_r
;
d
.
dirnext_r
=
gbfs_dirnext_r
;
d
.
dirclose_r
=
gbfs_dirclose_r
;
dev_id
=
AddDevice
(
&
d
);
if
(
0
!=
set_default
)
setDefaultDevice
(
dev_id
);
return
1
;
}
examples/gbfs_stdio.h
View file @
b43ab5f2
...
...
@@ -31,7 +31,7 @@ the following restrictions:
extern
"C"
{
#endif
void
gbfs_init
(
int
set_default
);
int
gbfs_init
(
int
set_default
);
#ifdef __cplusplus
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment