source: trunk/include/stdlib.h @ 865

Revision 865, 8.9 KB checked in by reyalp, 3 years ago (diff)
  • add strtoul on all cameras. Only tested on a540 but perfect matches on all.
  • fix lua handling of hex constants that would set sign bit. Now (as in standard lua) treated as an unsigned value, rather than resulting in LONG_MAX. Note that arithmetic and comparisons on such values in lua will still treat them as signed!
  • use strtoul in luaB_tonumber(), as in stock lua.
  • 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
52struct  stat
53    {
54    unsigned long       st_dev;         //?
55    unsigned long       st_ino;         //?     
56    unsigned short      st_mode;        //?     
57    short               st_nlink;       //?     
58    short               st_uid;         //?     
59    short               st_gid;         //?     
60    unsigned long       st_atime;       //?     
61    unsigned long       st_mtime;       //?     
62    unsigned long       st_ctime;       //?     
63    unsigned long       st_size;       
64    long                st_blksize;     //?
65    long                st_blocks;      //?
66    unsigned char       st_attrib;
67    int                 reserved1;      //     
68    int                 reserved2;      //
69    int                 reserved3;      //
70    int                 reserved4;      //
71    int                 reserved5;      //
72    int                 reserved6;      //
73};
74
75#endif
76
77extern int rand(void);
78extern void* srand(unsigned int seed);
79
80extern void qsort (void *__base, int __nelem, int __size, int (*__cmp)(const void *__e1, const void *__e2));
81
82extern int isdigit(int c);
83extern int isspace(int c);
84extern int isalpha(int c);
85extern int isupper(int c);
86extern int islower(int c);
87extern int ispunct(int c);
88extern int isxdigit(int c);
89
90extern long sprintf(char *s, const char *st, ...);
91
92extern long strlen(const char *s);
93extern int strcmp(const char *s1, const char *s2);
94extern int strncmp(const char *s1, const char *s2, long n);
95extern char *strchr(const char *s, int c);
96extern char *strcpy(char *dest, const char *src);
97extern char *strncpy(char *dest, const char *src, long n);
98extern char *strcat(char *dest, const char *app);
99extern char *strrchr(const char *s, int c);
100extern char *strpbrk(const char *s, const char *accept);
101
102extern long strtol(const char *nptr, char **endptr, int base);
103extern unsigned long strtoul(const char *nptr, char **endptr, int base);
104#define atoi(n) strtol((n),NULL,0)
105
106extern int tolower(int c);
107extern int toupper(int c);
108
109extern void *malloc(long size);
110extern void free(void *p);
111extern void *umalloc(long size);
112extern void ufree(void *p);
113
114extern void *memcpy(void *dest, const void *src, long n);
115extern void *memset(void *s, int c, int n);
116extern int memcmp(const void *s1, const void *s2, long n);
117extern void *memchr(const void *s, int c, int n);
118
119
120extern void SleepTask(long msec);
121extern long taskLock();
122extern long taskUnlock();
123
124extern long Fopen_Fut(const char *filename, const char *mode);
125extern long Fclose_Fut(long file);
126extern long Fread_Fut(void *buf, long elsize, long count, long f);
127extern long Fwrite_Fut(const void *buf, long elsize, long count, long f);
128extern long Fseek_Fut(long file, long offset, long whence);
129// TODO can we just use these all the time ?
130extern long RenameFile_Fut(const char *oldname, const char *newname);
131extern long MakeDirectory_Fut(const char *name);
132extern long DeleteFile_Fut(const char *name);
133extern long Feof_Fut(long file);
134extern long Fflush_Fut(long file);
135extern char *Fgets_Fut(char *buf, int n, long f);
136
137extern int creat (const char *name, int flags);
138extern int open (const char *name, int flags, int mode );
139extern int close (int fd);
140extern int write (int fd, const void *buffer, long nbytes);
141extern int read (int fd, void *buffer, long nbytes);
142extern int lseek (int fd, long offset, int whence);
143extern long mkdir(const char *dirname);
144
145// reverse engineered file struct. Appears to be valid for both vxworks and dryos
146// don't use this directly unless you absolutely need to
147// don't EVER try to create one yourself, as this isn't the full structure.
148typedef struct FILE_S {
149    int fd;         // used by Read/Write
150    unsigned len;   // +4 verfied in Fseek_FileStream
151    int unk0;       // +8
152    unsigned pos;   // +0xC verified in Fseek_FileStream
153    // unk1;        // +0x10
154    // unk2;        // +0x14
155    // io_buf;      // +0x18 32k uncached allocated in Fopen_FileStream
156    // unk3;        // +0x20 related to StartFileAccess_Sem
157    // ...name
158} FILE;
159// these tiny inlines provide type safety, and should optimize away
160static inline FILE *fopen(const char *filename, const char *mode) {
161    return (FILE *)Fopen_Fut(filename,mode);
162}
163static inline long fclose(FILE *f) {
164    return Fclose_Fut((long)f);
165}
166static inline long fread(void *buf, long elsize, long count, FILE *f) {
167    return Fread_Fut(buf,elsize,count,(long)f);
168}
169static inline long fwrite(const void *buf, long elsize, long count, FILE *f) {
170    return Fwrite_Fut(buf,elsize,count,(long)f);
171}
172static inline long fseek(FILE *file, long offset, long whence) {
173    return Fseek_Fut((long)file,offset,whence);
174}
175static inline long fflush(FILE *file) {
176    return Fflush_Fut((long)file);
177}
178static inline long feof(FILE *file) {
179    return Feof_Fut((long)file);
180}
181static inline long ftell(FILE *file) {
182    if(!file) return -1;
183    return file->pos;
184}
185static inline char *fgets(char *buf, int n, FILE *f) {
186    return Fgets_Fut(buf,n,(int)f);
187}
188#define fdelete(a) DeleteFile_Fut(a)
189/**
190 * No STUBS!
191 * You can't use these two directly from THUMB code (core), only from platform.
192 */
193extern int fprintf(FILE *fd, char*buf, ...);
194extern int printf(char *buf, ...);
195
196extern void msleep(long msec);
197extern long task_lock();
198extern long task_unlock();
199extern const char *task_name(int id);
200int task_id_list_get(int *idlist,int size);
201extern const char *strerror(int num);
202// on vxworks we could find the actual errno, but this is easier to automate sig
203// doesn't exist on dryos, but we stub it
204extern int errnoOfTaskGet(int tid);
205#define errno (errnoOfTaskGet(0))
206
207#define DOS_ATTR_RDONLY         0x01            /* read-only file */
208#define DOS_ATTR_HIDDEN         0x02            /* hidden file */
209#define DOS_ATTR_SYSTEM         0x04            /* system file */
210#define DOS_ATTR_VOL_LABEL      0x08            /* volume label (not a file) */
211#define DOS_ATTR_DIRECTORY      0x10            /* entry is a sub-directory */
212#define DOS_ATTR_ARCHIVE        0x20            /* file subject to archiving */
213
214#if !CAM_DRYOS
215struct dirent {
216    char                d_name[100];
217};
218#else
219struct dirent {
220    char                d_name[13];
221    unsigned long       unk1;
222    unsigned char       attrib;
223    unsigned long       size;
224    unsigned long       time1;
225    unsigned long       time2;
226    unsigned long       time3;
227};
228#endif
229
230typedef struct {
231    unsigned int        fd;
232    unsigned int        loc;
233    struct dirent       dir;
234} DIR;
235
236
237
238extern DIR*           opendir (const char* name);
239extern struct dirent* readdir (DIR*);
240extern int            closedir (DIR*);
241extern void           rewinddir (DIR*);
242extern int            stat (const char *name, struct stat *pStat);
243
244
245struct tm
246        {
247        int tm_sec;     /* seconds after the minute     - [0, 59] */
248        int tm_min;     /* minutes after the hour       - [0, 59] */
249        int tm_hour;    /* hours after midnight         - [0, 23] */
250        int tm_mday;    /* day of the month             - [1, 31] */
251        int tm_mon;     /* months since January         - [0, 11] */
252        int tm_year;    /* years since 1900     */
253        int tm_wday;    /* days since Sunday            - [0, 6] */
254        int tm_yday;    /* days since January 1         - [0, 365] */
255        int tm_isdst;   /* Daylight Saving Time flag */
256        };
257
258typedef unsigned long time_t;
259
260extern struct tm * localtime(const unsigned long *_tod);
261
262extern int rename(const char *oldname, const char *newname);
263extern int chdir(char *pathname);
264extern int remove(const char *name);
265#ifdef FS_USE_FUT
266#define mkdir(x) MakeDirectory_Fut(x)
267#define rename(x,y) RenameFile_Fut(x,y)
268#define remove(x) DeleteFile_Fut(x)
269#endif
270struct utimbuf {
271    unsigned long actime;       /* set the access time */
272    unsigned long modtime;      /* set the modification time */
273};
274
275extern int utime(const char *file, struct utimbuf *newTimes);
276extern unsigned long time(unsigned long *timer);
277extern long strftime(char *s, unsigned long maxsize, const char *format, const struct tm *timp);
278extern time_t mktime(struct tm *timp);
279
280static inline int abs( int v ) {
281  return v<0 ? -v : v;
282}
283
284#endif
Note: See TracBrowser for help on using the repository browser.