root/include/stdlib.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


   1 #ifndef STDLIB_H
   2 #define STDLIB_H
   3 
   4 // CHDK stdlib
   5 
   6 // Note: used in modules and platform independent code. 
   7 // Do not add platform dependent stuff in here (#ifdef/#endif compile options or camera dependent values)
   8 
   9 //==========================================================
  10 
  11 #include "versions.h"
  12 
  13 // Structures to store user configurable color entry
  14 #pragma pack(1)     // make sure they are packed as tightly as possible
  15 
  16 typedef struct {
  17     unsigned char   col;        // color value
  18     unsigned char   type;       // 0 = Canon palette index, 1 = CHDK color index (chdk_colors)
  19 } chdkColor;
  20 
  21 typedef struct {
  22     chdkColor       fg;         // foreground
  23     chdkColor       bg;         // background
  24 } confColor;
  25 
  26 #pragma pack()
  27 
  28 typedef int             coord;
  29 typedef unsigned char   color;
  30 typedef unsigned short  twoColors;
  31 
  32 #define MAKE_COLOR(bg, fg)  ((twoColors)(((color)(bg) << 8) | (color)(fg)))
  33 #define FG_COLOR(c)         ((color)(c     ))
  34 #define BG_COLOR(c)         ((color)(c >> 8))
  35 
  36 //==========================================================
  37 
  38 #define NULL            ((void*)0)
  39 
  40 #define SEEK_SET        0
  41 #define SEEK_CUR        1
  42 #define SEEK_END        2
  43 
  44 #define O_RDONLY        0
  45 #define O_WRONLY        1
  46 #define O_RDWR          2
  47 #define O_APPEND        8   // DryOS only, wrapper code will removed this for VxWorks so file will be overwritten instead of appended
  48 
  49 // CHDK defined values - note does not match VxWorks values
  50 // Values are corrected in 'open' function to match OS requirements
  51 #define O_TRUNC         0x200
  52 #define O_CREAT         0x100
  53 
  54 // CHDK 'stat' structure - does not match VxWorks or DryOS internal structs
  55 // Converted in stat function (generic/wrappers.c)
  56 // This is the minimal set of values now available from the firmware
  57 struct stat
  58 {
  59     unsigned long       st_attrib;
  60     unsigned long       st_size;
  61     unsigned long       st_ctime;
  62     unsigned long       st_mtime;
  63 };
  64 
  65 extern int rand(void);
  66 extern void* srand(unsigned int seed);
  67 
  68 extern void qsort (void *__base, int __nelem, int __size, int (*__cmp)(const void *__e1, const void *__e2));
  69 
  70 extern int isdigit(int c);
  71 extern int isspace(int c);
  72 extern int isalpha(int c);
  73 extern int isupper(int c);
  74 extern int islower(int c);
  75 extern int ispunct(int c);
  76 extern int isxdigit(int c);
  77 extern int iscntrl(int c);
  78 extern int isalnum(int c);
  79 
  80 extern long sprintf(char *s, const char *st, ...);
  81 
  82 extern long strlen(const char *s);
  83 extern int strcmp(const char *s1, const char *s2);
  84 extern int strncmp(const char *s1, const char *s2, long n);
  85 extern char *strchr(const char *s, int c);
  86 extern char *strcpy(char *dest, const char *src);
  87 extern char *strncpy(char *dest, const char *src, long n);
  88 extern char *strcat(char *dest, const char *app);
  89 extern char *strrchr(const char *s, int c);
  90 extern char *strpbrk(const char *s, const char *accept);
  91 extern char *strstr(const char *s, const char *s2);
  92 
  93 extern long strtol(const char *nptr, char **endptr, int base);
  94 extern unsigned long strtoul(const char *nptr, char **endptr, int base);
  95 #define atoi(n) strtol((n),NULL,0)
  96 
  97 extern int tolower(int c);
  98 extern int toupper(int c);
  99 
 100 extern void *malloc(long size);
 101 extern void free(void *p);
 102 extern void *umalloc(long size);
 103 extern void ufree(void *p);
 104 
 105 extern void *memcpy(void *dest, const void *src, long n);
 106 extern void *memset(void *s, int c, int n);
 107 extern int memcmp(const void *s1, const void *s2, long n);
 108 extern void *memchr(const void *s, int c, int n);
 109 
 110 extern void SleepTask(long msec);
 111 extern long taskLock();
 112 extern long taskUnlock();
 113 
 114 extern int creat (const char *name, int flags);
 115 extern int open (const char *name, int flags, int mode );
 116 extern int close (int fd);
 117 extern int write (int fd, const void *buffer, long nbytes);
 118 extern int read (int fd, void *buffer, long nbytes);
 119 extern int lseek (int fd, long offset, int whence);
 120 extern long mkdir(const char *dirname);
 121 extern long mkdir_if_not_exist(const char *dirname);
 122 extern int rename(const char *oldname, const char *newname);
 123 extern int chdir(char *pathname);
 124 extern int remove(const char *name);
 125 extern int stat (const char *name, struct stat *pStat);
 126 
 127 extern unsigned char SetFileAttributes(const char* fn, unsigned char attr);
 128 
 129 // reverse engineered file struct. Appears to be valid for both vxworks and dryos
 130 // don't use this directly unless you absolutely need to
 131 // don't EVER try to create one yourself, as this isn't the full structure.
 132 typedef struct FILE_S {
 133     int fd;         // used by Read/Write
 134     unsigned len;   // +4 verfied in Fseek_FileStream
 135     int unk0;       // +8
 136     unsigned pos;   // +0xC verified in Fseek_FileStream
 137     // unk1;        // +0x10 
 138     // unk2;        // +0x14
 139     // io_buf;      // +0x18 32k uncached allocated in Fopen_FileStream
 140     // unk3;        // +0x20 related to StartFileAccess_Sem
 141     // ...name
 142 } FILE;
 143 
 144 extern FILE *fopen(const char *filename, const char *mode);
 145 extern long fclose(FILE *f);
 146 extern long fread(void *buf, long elsize, long count, FILE *f);
 147 extern long fwrite(const void *buf, long elsize, long count, FILE *f);
 148 extern long fseek(FILE *file, long offset, long whence);
 149 extern long fflush(FILE *file);
 150 extern long feof(FILE *file);
 151 extern long ftell(FILE *file);
 152 extern char *fgets(char *buf, int n, FILE *f);
 153 
 154 extern void msleep(long msec);
 155 extern long task_lock();
 156 extern long task_unlock();
 157 extern const char *task_name(int id);
 158 int task_id_list_get(int *idlist,int size);
 159 extern const char *strerror(int num);
 160 // on vxworks we could find the actual errno, but this is easier to automate sig
 161 // doesn't exist on dryos, but we stub it
 162 extern int errnoOfTaskGet(int tid);
 163 #define errno (errnoOfTaskGet(0))
 164 
 165 //-------------------------------------------------------------------------------------
 166 
 167 #define DOS_ATTR_RDONLY         0x01            /* read-only file */
 168 #define DOS_ATTR_HIDDEN         0x02            /* hidden file */
 169 #define DOS_ATTR_SYSTEM         0x04            /* system file */
 170 #define DOS_ATTR_VOL_LABEL      0x08            /* volume label (not a file) */
 171 #define DOS_ATTR_DIRECTORY      0x10            /* entry is a sub-directory */
 172 #define DOS_ATTR_ARCHIVE        0x20            /* file subject to archiving */
 173 
 174 //-------------------------------------------------------------------------------------
 175 
 176 // CHDK structs for opendir/readdir/closedir
 177 // Conversion to/from camera specific versions done in wrapper code
 178 struct dirent   // Returned from readdir
 179 {
 180     char            d_name[100];    // We only use the name value
 181 };
 182 
 183 // Returned from opendir
 184 typedef struct
 185 {
 186     void            *cam_DIR;   // Camera specific internal DIR structure
 187     int             fw_dir;     // 1 if firmware function is used, 0 if CHDK implementation
 188     struct dirent   dir;        // Last info returned from readdir
 189 } DIR;
 190 
 191 // opendir_chdk has non-standard second arg
 192 #define OPENDIR_FL_NONE     0x0 
 193 #define OPENDIR_FL_CHDK_LFN 0x1 // use CHDK long file name support, if available.
 194                                // No effect on VxWorks, which supports LFNs natively
 195                                // Non-CHDK LFN support on DryOS varies by OS version and filesystem
 196 extern DIR*           opendir (const char* name); // wrapper of opendir_chdk(name,FL_NONE) for easy compatibility
 197 extern DIR*           opendir_chdk (const char* name,unsigned flags);
 198 extern struct dirent* readdir (DIR*);
 199 extern int            closedir (DIR*);
 200 //extern void           rewinddir (DIR*);   // Not used
 201 
 202 //-------------------------------------------------------------------------------------
 203 
 204 struct tm
 205         {
 206         int tm_sec;     /* seconds after the minute     - [0, 59] */
 207         int tm_min;     /* minutes after the hour       - [0, 59] */
 208         int tm_hour;    /* hours after midnight         - [0, 23] */
 209         int tm_mday;    /* day of the month             - [1, 31] */
 210         int tm_mon;     /* months since January         - [0, 11] */
 211         int tm_year;    /* years since 1900     */
 212         int tm_wday;    /* days since Sunday            - [0, 6] */
 213         int tm_yday;    /* days since January 1         - [0, 365] */
 214         int tm_isdst;   /* Daylight Saving Time flag */
 215         };
 216 
 217 typedef unsigned long time_t;
 218 
 219 extern struct tm * localtime(const time_t *_tod);
 220 extern struct tm * get_localtime();
 221 
 222 struct utimbuf {
 223     unsigned long actime;       /* set the access time */
 224     unsigned long modtime;      /* set the modification time */
 225 };
 226 
 227 extern int utime(const char *file, struct utimbuf *newTimes);
 228 extern unsigned long time(unsigned long *timer);
 229 extern long strftime(char *s, unsigned long maxsize, const char *format, const struct tm *timp);
 230 extern time_t mktime(struct tm *timp);
 231 
 232 extern int abs( int v );
 233 
 234 //---------------------------------------------------------------
 235 // Semaphore & Assert
 236 
 237 extern void DebugAssert(char*, int);
 238 
 239 extern int CreateBinarySemaphore(char* name, int init);
 240 extern int TakeSemaphore(int sem, int timeout);
 241 extern void GiveSemaphore(int sem);
 242 
 243 //---------------------------------------------------------------
 244 
 245 #endif

/* [<][>][^][v][top][bottom][index][help] */