source: trunk/include/stdlib.h @ 1119

Revision 1119, 8.2 KB checked in by reyalP, 2 years ago (diff)

stidio inline cleanup from philmoz in http://chdk.setepontos.com/index.php?topic=650.msg63691#msg63691

  • Property svn:eol-style set to native
Line 
1#include "camera.h"
2
3#ifndef STDLIB_H
4#define STDLIB_H
5
6#define NULL            ((void*)0)
7
8#define SEEK_SET        0
9#define SEEK_CUR        1
10#define SEEK_END        2
11
12#define O_RDONLY        0
13#define O_WRONLY        1
14#define O_RDWR          2
15
16
17#if !CAM_DRYOS
18
19#define O_TRUNC         0x400
20#define O_CREAT         0x200
21
22struct  stat
23    {
24    unsigned long       st_dev;         /* device ID number */
25    unsigned long       st_ino;         /* file serial number */
26    unsigned short      st_mode;        /* file mode (see below) */
27    short               st_nlink;       /* number of links to file */
28    short               st_uid;         /* user ID of file's owner */
29    short               st_gid;         /* group ID of file's group */
30    unsigned long       st_rdev;        /* device ID, only if special file */
31    unsigned long       st_size;        /* size of file, in bytes */
32    unsigned long       st_atime;       /* time of last access */
33    unsigned long       st_mtime;       /* time of last modification */
34    unsigned long       st_ctime;       /* time of last change of file status */
35    long                st_blksize;
36    long                st_blocks;
37    unsigned char       st_attrib;      /* file attribute byte (dosFs only) */
38    int                 reserved1;      /* reserved for future use */
39    int                 reserved2;      /* reserved for future use */
40    int                 reserved3;      /* reserved for future use */
41    int                 reserved4;      /* reserved for future use */
42    int                 reserved5;      /* reserved for future use */
43    int                 reserved6;      /* reserved for future use */
44};
45
46#else
47
48#define O_APPEND        0x8 // ok for dryos, vx?
49#define O_TRUNC         0x200
50#define O_CREAT         0x100
51
52#ifndef CAM_DRYOS_2_3_R39
53struct  stat
54    {
55    unsigned long       st_dev;         //?
56    unsigned long       st_ino;         //?
57    unsigned short      st_mode;        //?
58    short               st_nlink;       //?
59    short               st_uid;         //?
60    short               st_gid;         //?
61    unsigned long       st_atime;       //?
62    unsigned long       st_mtime;       //?
63    unsigned long       st_ctime;       //?
64    unsigned long       st_size;
65    long                st_blksize;     //?
66    long                st_blocks;      //?
67    unsigned char       st_attrib;
68    int                 reserved1;      //
69    int                 reserved2;      //
70    int                 reserved3;      //
71    int                 reserved4;      //
72    int                 reserved5;      //
73    int                 reserved6;      //
74};
75
76#else
77struct  stat
78    {
79    unsigned long       st_unknown_1;
80    unsigned long       st_attrib;
81    unsigned long       st_size;
82    unsigned long       st_ctime;
83    unsigned long       st_mtime;
84    unsigned long       st_unknown_2;
85};
86#endif//CAM_DRYOS_2_3_R39
87
88#endif
89
90extern int rand(void);
91extern void* srand(unsigned int seed);
92
93extern void qsort (void *__base, int __nelem, int __size, int (*__cmp)(const void *__e1, const void *__e2));
94
95extern int isdigit(int c);
96extern int isspace(int c);
97extern int isalpha(int c);
98extern int isupper(int c);
99extern int islower(int c);
100extern int ispunct(int c);
101extern int isxdigit(int c);
102extern int iscntrl(int c);
103extern int isalnum(int c);
104
105extern long sprintf(char *s, const char *st, ...);
106
107extern long strlen(const char *s);
108extern int strcmp(const char *s1, const char *s2);
109extern int strncmp(const char *s1, const char *s2, long n);
110extern char *strchr(const char *s, int c);
111extern char *strcpy(char *dest, const char *src);
112extern char *strncpy(char *dest, const char *src, long n);
113extern char *strcat(char *dest, const char *app);
114extern char *strrchr(const char *s, int c);
115extern char *strpbrk(const char *s, const char *accept);
116
117extern long strtol(const char *nptr, char **endptr, int base);
118extern unsigned long strtoul(const char *nptr, char **endptr, int base);
119#define atoi(n) strtol((n),NULL,0)
120
121extern int tolower(int c);
122extern int toupper(int c);
123
124extern void *malloc(long size);
125extern void free(void *p);
126extern void *umalloc(long size);
127extern void ufree(void *p);
128
129extern void *memcpy(void *dest, const void *src, long n);
130extern void *memset(void *s, int c, int n);
131extern int memcmp(const void *s1, const void *s2, long n);
132extern void *memchr(const void *s, int c, int n);
133
134
135extern void SleepTask(long msec);
136extern long taskLock();
137extern long taskUnlock();
138
139// TODO can we just use these all the time ?
140extern long RenameFile_Fut(const char *oldname, const char *newname);
141extern long MakeDirectory_Fut(const char *name);
142extern long DeleteFile_Fut(const char *name);
143
144extern int creat (const char *name, int flags);
145extern int open (const char *name, int flags, int mode );
146extern int close (int fd);
147extern int write (int fd, const void *buffer, long nbytes);
148extern int read (int fd, void *buffer, long nbytes);
149extern int lseek (int fd, long offset, int whence);
150extern long mkdir(const char *dirname);
151
152// reverse engineered file struct. Appears to be valid for both vxworks and dryos
153// don't use this directly unless you absolutely need to
154// don't EVER try to create one yourself, as this isn't the full structure.
155typedef struct FILE_S {
156    int fd;         // used by Read/Write
157    unsigned len;   // +4 verfied in Fseek_FileStream
158    int unk0;       // +8
159    unsigned pos;   // +0xC verified in Fseek_FileStream
160    // unk1;        // +0x10
161    // unk2;        // +0x14
162    // io_buf;      // +0x18 32k uncached allocated in Fopen_FileStream
163    // unk3;        // +0x20 related to StartFileAccess_Sem
164    // ...name
165} FILE;
166
167extern FILE *fopen(const char *filename, const char *mode);
168extern long fclose(FILE *f);
169extern long fread(void *buf, long elsize, long count, FILE *f);
170extern long fwrite(const void *buf, long elsize, long count, FILE *f);
171extern long fseek(FILE *file, long offset, long whence);
172extern long fflush(FILE *file);
173extern long feof(FILE *file);
174extern long ftell(FILE *file);
175extern char *fgets(char *buf, int n, FILE *f);
176#define fdelete(a) DeleteFile_Fut(a)
177
178/**
179 * No STUBS!
180 * You can't use these two directly from THUMB code (core), only from platform.
181 */
182extern int fprintf(FILE *fd, char*buf, ...);
183extern int printf(char *buf, ...);
184
185extern void msleep(long msec);
186extern long task_lock();
187extern long task_unlock();
188extern const char *task_name(int id);
189int task_id_list_get(int *idlist,int size);
190extern const char *strerror(int num);
191// on vxworks we could find the actual errno, but this is easier to automate sig
192// doesn't exist on dryos, but we stub it
193extern int errnoOfTaskGet(int tid);
194#define errno (errnoOfTaskGet(0))
195
196#define DOS_ATTR_RDONLY         0x01            /* read-only file */
197#define DOS_ATTR_HIDDEN         0x02            /* hidden file */
198#define DOS_ATTR_SYSTEM         0x04            /* system file */
199#define DOS_ATTR_VOL_LABEL      0x08            /* volume label (not a file) */
200#define DOS_ATTR_DIRECTORY      0x10            /* entry is a sub-directory */
201#define DOS_ATTR_ARCHIVE        0x20            /* file subject to archiving */
202
203#if !CAM_DRYOS
204struct dirent {
205    char                d_name[100];
206};
207#else
208struct dirent {
209    char                d_name[13];
210    unsigned long       unk1;
211    unsigned char       attrib;
212    unsigned long       size;
213    unsigned long       time1;
214    unsigned long       time2;
215    unsigned long       time3;
216};
217#endif
218
219typedef struct {
220    unsigned int        fd;
221    unsigned int        loc;
222    struct dirent       dir;
223} DIR;
224
225
226
227extern DIR*           opendir (const char* name);
228extern struct dirent* readdir (DIR*);
229extern int            closedir (DIR*);
230extern void           rewinddir (DIR*);
231extern int            stat (const char *name, struct stat *pStat);
232
233
234struct tm
235        {
236        int tm_sec;     /* seconds after the minute     - [0, 59] */
237        int tm_min;     /* minutes after the hour       - [0, 59] */
238        int tm_hour;    /* hours after midnight         - [0, 23] */
239        int tm_mday;    /* day of the month             - [1, 31] */
240        int tm_mon;     /* months since January         - [0, 11] */
241        int tm_year;    /* years since 1900     */
242        int tm_wday;    /* days since Sunday            - [0, 6] */
243        int tm_yday;    /* days since January 1         - [0, 365] */
244        int tm_isdst;   /* Daylight Saving Time flag */
245        };
246
247typedef unsigned long time_t;
248
249extern struct tm * localtime(const unsigned long *_tod);
250
251extern int rename(const char *oldname, const char *newname);
252extern int chdir(char *pathname);
253extern int remove(const char *name);
254#ifdef FS_USE_FUT
255#define mkdir(x) MakeDirectory_Fut(x)
256#define rename(x,y) RenameFile_Fut(x,y)
257#define remove(x) DeleteFile_Fut(x)
258#endif
259struct utimbuf {
260    unsigned long actime;       /* set the access time */
261    unsigned long modtime;      /* set the modification time */
262};
263
264extern int utime(const char *file, struct utimbuf *newTimes);
265extern unsigned long time(unsigned long *timer);
266extern long strftime(char *s, unsigned long maxsize, const char *format, const struct tm *timp);
267extern time_t mktime(struct tm *timp);
268
269extern int abs( int v );
270
271#endif
Note: See TracBrowser for help on using the repository browser.