]> git.saurik.com Git - wxWidgets.git/blob - src/palmos/stdall.c
oops, added missing #endif
[wxWidgets.git] / src / palmos / stdall.c
1 /******************************************************************************
2 * Name: src/palmos/stdall.c
3 * Purpose: the missing functions of Palm OS for wxPalm
4 * Author: Yunhui Fu
5 * Created: 2007-10-18
6 * Modified by:
7 * RCS-ID: $Id$
8 * Copyright: (c) 2007 Yunhui Fu
9 * Licence: wxWindows licence
10 ******************************************************************************/
11
12 #include <Preferences.h> // Core/System/
13 #include <DateTime.h> //Core/System/, DateToAscii() etc.
14 #include <TimeMgr.h> //Core/System/, TimGetTicks()
15
16 #include "wx/defs.h"
17 #define PALMOS_TRACE(msg) ErrFatalErrorInContext(__FILE__, __LINE__, msg)
18
19 #if __WXPALMOS6__
20
21 #ifdef TARGET_PLATFORM
22 #if TARGET_PLATFORM != TARGET_PLATFORM_PALMSIM_WIN32
23 void
24 exit (int exitno)
25 {
26 }
27 #endif
28 #endif
29
30 #else
31
32 #define SEC_1904_1970 2082844800LU//0x7C25B080 // 0x7C25B080 == 2082844800LU
33
34 time_t
35 time (time_t *T)
36 {
37 UInt32 sec;
38 // UInt32 TimGetSeconds(void); // seconds since 1/1/1904
39 // void TimSetSeconds (UInt32 seconds); // seconds since 1/1/1904
40 // UInt32 TimGetTicks(void); // ticks since power on
41 sec = TimGetSeconds ();
42 if (T) {
43 *T = sec - SEC_1904_1970;
44 }
45 return (sec - SEC_1904_1970);
46 }
47
48 static struct tm *
49 palmtimet2unixtm (const time_t t, struct tm *ptm)
50 {
51 DateTimeType dt;
52 memset (&dt, 0, sizeof (dt));
53 memset (ptm, 0, sizeof (*ptm));
54 TimSecondsToDateTime (t, &dt);
55 ptm->tm_sec = dt.second;
56 ptm->tm_min = dt.minute;
57 ptm->tm_hour = dt.hour;
58 ptm->tm_mday = dt.day;
59 ptm->tm_mon = dt.month;
60 ptm->tm_year = dt.year;
61 ptm->tm_wday = dt.weekDay;
62
63 //ptm->tm_wday = DayOfWeek (dt.month, dt.day, dt.year);
64 //ptm->tm_mday = DayOfMonth (dt.month, dt.day, dt.year);
65 return ptm;
66 }
67
68 struct tm *
69 gmtime_r (const time_t *pt, struct tm *ptm)
70 {
71 UInt32 utcTime;
72 Int16 timeZone = PrefGetPreference(prefTimeZone);
73 Int16 daylightSavingAdjustment = PrefGetPreference(prefDaylightSavingAdjustment);
74
75 if ((NULL == pt) || (NULL == ptm)) {
76 return NULL;
77 }
78 utcTime = TimTimeZoneToUTC (*pt + SEC_1904_1970, timeZone, daylightSavingAdjustment);
79 palmtimet2unixtm (utcTime, ptm);
80 return ptm;
81 }
82
83 struct tm *
84 localtime_r (const time_t *pt, struct tm *ptm)
85 {
86 UInt32 utcTime;
87 Int16 timeZone = PrefGetPreference(prefTimeZone);
88 Int16 daylightSavingAdjustment = PrefGetPreference(prefDaylightSavingAdjustment);
89 if ((NULL == pt) || (NULL == ptm)) {
90 return NULL;
91 }
92 utcTime = TimUTCToTimeZone (*pt + SEC_1904_1970, timeZone, daylightSavingAdjustment);
93 palmtimet2unixtm (utcTime, ptm);
94 return ptm;
95 }
96 /*
97 static struct tm g_gmtime_info;
98
99 struct tm *
100 gmtime (const time_t *CLOCK)
101 {
102 if (NULL == CLOCK) {
103 return NULL;
104 }
105 if (NULL == gmtime_r (CLOCK, &g_gmtime_info)) {
106 return NULL;
107 }
108 return &g_gmtime_info;
109 }
110 */
111 static struct tm g_localtime_info;
112
113 struct tm *
114 localtime (const time_t *CLOCK)
115 {
116 if (NULL == CLOCK) {
117 return NULL;
118 }
119 if (NULL == localtime_r (CLOCK, &g_localtime_info)) {
120 return NULL;
121 }
122 return &g_localtime_info;
123 }
124
125 static char * g_strftime_wdayconv[][2] = {
126 {"Sun", "Sunday"},
127 {"Mon", "Monday"},
128 {"Tue", "Tuesday"},
129 {"Wed", "Wednesday"},
130 {"Thu", "Thursday"},
131 {"Fri", "Friday"},
132 {"Sat", "Saturday"},
133 };
134
135 static char * g_strftime_monconv[][2] = {
136 {"Jan", "January"},
137 {"Feb", "Febuary"},
138 {"Mar", "March"},
139 {"Apr", "April"},
140 {"May", "May"},
141 {"Jun", "June"},
142 {"Jul", "July"},
143 {"Aug", "August"},
144 {"Sep", "September"},
145 {"Oct", "October"},
146 {"Nov", "November"},
147 {"Dec", "December"},
148 };
149 #define SFCONV_ABBR 0
150 #define SFCONV_FULL 1
151
152 size_t
153 strftime (char *buf, size_t sz_buf, const char *fmt, const struct tm *ptm)
154 {
155 char *p;
156 char *pret;
157 if ((timeStringLength > sz_buf) || (strlen (fmt) < 1)) {
158 return 0;
159 }
160 memset (buf, 0, sz_buf);
161 p = fmt;
162 pret = buf;
163 for (; *p != '\0';) {
164 if ('%' == *p) {
165 p ++;
166 if (*p == '\0') {
167 break;
168 }
169 // FIXME: test the overflow of the buffer
170 switch (*p) {
171 case 'a':
172 strcpy (pret, g_strftime_wdayconv[ptm->tm_wday % 7][SFCONV_ABBR]);
173 pret += 3;
174 break;
175 case 'A':
176 strcpy (pret, g_strftime_wdayconv[ptm->tm_wday % 7][SFCONV_FULL]);
177 pret += strlen (g_strftime_wdayconv[ptm->tm_wday % 7][SFCONV_FULL]);
178 break;
179 case 'b':
180 strcpy (pret, g_strftime_monconv[ptm->tm_mon % 12][SFCONV_ABBR]);
181 pret += 3;
182 break;
183 case 'B':
184 strcpy (pret, g_strftime_monconv[ptm->tm_mon % 12][SFCONV_FULL]);
185 pret += strlen (g_strftime_monconv[ptm->tm_mon % 12][SFCONV_FULL]);
186 break;
187 case 'c':
188 strcpy (pret, g_strftime_wdayconv[ptm->tm_wday % 7][SFCONV_ABBR]);
189 pret += 3;
190 *pret = ' ';
191 pret ++;
192 strcpy (pret, g_strftime_monconv[ptm->tm_mon % 12][SFCONV_ABBR]);
193 pret += 3;
194 *pret = ' ';
195 pret ++;
196 sprintf (pret, "%d %02d:%02d:%02d %d", ptm->tm_mday,
197 ptm->tm_hour, ptm->tm_min, ptm->tm_sec, ptm->tm_year);
198 pret += strlen (pret);
199 break;
200 case 'd':
201 sprintf (pret, "%02d", ptm->tm_mday % 31);
202 pret += 2;
203 break;
204 case 'H':
205 sprintf (pret, "%02d", ptm->tm_hour % 24);
206 pret += 2;
207 break;
208 case 'I':
209 sprintf (pret, "%02d", (ptm->tm_hour % 12) + 1);
210 pret += 2;
211 break;
212 case 'j':
213 sprintf (pret, "%03d", ptm->tm_year % 400);
214 pret += 3;
215 break;
216 case 'm':
217 sprintf (pret, "%02d", (ptm->tm_mon % 12) + 1);
218 pret += 2;
219 break;
220 case 'M':
221 sprintf (pret, "%02d", ptm->tm_min % 60);
222 pret += 2;
223 break;
224 case 'p':
225 if (ptm->tm_hour > 12) {
226 strcpy (pret, "PM");
227 break;
228 }
229 strcpy (pret, "AM");
230 pret += 2;
231 break;
232 case 'S':
233 sprintf (pret, "%02d", ptm->tm_sec % 61);
234 pret += 2;
235 break;
236 case 'U':
237 // FIXME: Week number with the first Sunday as the first day of week one (00-53)
238 sprintf (pret, "%02d", ptm->tm_yday / 7);
239 pret += 2;
240 break;
241 case 'w':
242 sprintf (pret, "%d", ptm->tm_wday % 7);
243 pret += 1;
244 break;
245 case 'W':
246 // FIXME: Week number with the first Sunday as the first day of week one (00-53)
247 sprintf (pret, "%02d", ptm->tm_yday / 7);
248 pret += 2;
249 break;
250 case 'x':
251 sprintf (pret, "%02d/%02d/%02d",
252 ptm->tm_mon, ptm->tm_mday, ptm->tm_year - 1900);
253 pret += strlen (pret);
254 break;
255 case 'X':
256 sprintf (pret, "%02d:%02d:%02d",
257 ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
258 pret += strlen (pret);
259 break;
260 case 'y':
261 sprintf (pret, "%02d", ptm->tm_year - 1900);
262 pret += 2;
263 break;
264 case 'Y':
265 sprintf (pret, "%02d", ptm->tm_year);
266 pret += strlen (pret);
267 break;
268 case 'Z':
269 {
270 LmLocaleType ll;
271 ll.language = lmAnyLanguage;
272 ll.country = 0;
273 TimeZoneToAscii (ptm->tm_gmtoff, &ll, pret);
274 }
275 pret += strlen (pret);
276 break;
277 case '%':
278 *pret = *p;
279 pret ++;
280 break;
281 }
282 } else {
283 *pret = *p;
284 pret ++;
285 }
286 p ++;
287 }
288 return 0;
289 }
290
291 time_t
292 mktime (struct tm *ptm)
293 {
294 DateTimeType dt;
295 if (NULL == ptm) {
296 return 0;
297 }
298 memset (&dt, 0, sizeof (dt));
299 dt.second = ptm->tm_sec;
300 dt.minute = ptm->tm_min;
301 dt.hour = ptm->tm_hour;
302 dt.day = ptm->tm_mday;
303 dt.month = ptm->tm_mon;
304 dt.year = ptm->tm_year;
305 dt.weekDay = ptm->tm_wday;
306 return TimDateTimeToSeconds (&dt);
307 }
308
309 int
310 vsscanf (const char *s, const char *format, va_list param)
311 {
312 return -1;
313 }
314
315 FILE * fopen (const char *_name, const char *_type) {return NULL;}
316 int fclose (FILE *fp) {return 0;}
317 size_t fread (void *buf, size_t _size, size_t _n, FILE *fp) {return 0;}
318 size_t fwrite (const void *buf , size_t _size, size_t _n, FILE *fp) {return 0;}
319 int fseek (FILE *fp, long offset, int whence) {return -1;}
320 long ftell (FILE *fp) {return -1;}
321 int feof (FILE *fp) {return -1;}
322 int ferror (FILE *fp) {return -1;}
323 void clearerr (FILE *fp) {}
324
325 #endif // __WXPALMOS6__
326
327 #define _BIT_ALPHA 0X0001
328 #define _BIT_BLANK 0X0002
329 #define _BIT_CNTRL 0X0004
330 #define _BIT_DIGIT 0X0008
331 #define _BIT_GRAPH 0X0010
332 #define _BIT_LOWER 0X0020
333 #define _BIT_PRINT 0X0040
334 #define _BIT_PUNCT 0X0080
335 #define _BIT_SPACE 0X0100
336 #define _BIT_UPPER 0X0200
337 #define _BIT_XDIGIT 0X0400
338
339 int iswalnum(wint_t C) {return 0;}
340 int iswalpha(wint_t C) {return 0;}
341 int iswcntrl(wint_t C) {return 0;}
342 int iswdigit(wint_t C) {return 0;}
343 int iswgraph(wint_t C) {return 0;}
344 int iswlower(wint_t C) {return 0;}
345 int iswprint(wint_t C) {return 0;}
346 int iswpunct(wint_t C) {return 0;}
347 int iswspace(wint_t C) {return 0;}
348 int iswupper(wint_t C) {return 0;}
349 int iswxdigit(wint_t C) {return 0;}
350
351 wint_t towlower(wint_t C) {return 0;}
352 wint_t towupper(wint_t C) {return 0;}
353 size_t wcsftime(wchar_t *strDest, size_t maxsize, const wchar_t *format, const struct tm *timeptr) {return 0;}
354
355 size_t
356 wcslen (const wchar_t * str)
357 {
358 size_t i;
359 for (i = 0; str[i] != 0; i ++);
360 return i;
361 }
362
363 wchar_t *
364 wcscpy (wchar_t * dst, const wchar_t * src)
365 {
366 size_t len;
367 len = wcslen (src);
368 if (len < 1) {
369 return NULL;
370 }
371 memmove (dst, src, len * sizeof (wchar_t));
372 dst[len] = 0;
373 return dst;
374 }
375
376 wchar_t *
377 wcsncpy (wchar_t * dst, const wchar_t * src, size_t len_max)
378 {
379 size_t len;
380 len = wcslen (src);
381 if (len < 1) {
382 return NULL;
383 }
384 if (len_max < len + 1) {
385 len = len_max - 1;
386 }
387 if (len > 0) {
388 memmove (dst, src, len * sizeof (wchar_t));
389 }
390 dst[len] = 0;
391 return dst;
392 }
393
394 wchar_t *
395 wcscat (wchar_t * dst, const wchar_t * src)
396 {
397 size_t len_dst;
398 len_dst = wcslen (dst);
399 return wcscpy (dst + len_dst, src);
400 }
401
402 wchar_t *
403 wcsncat (wchar_t * dst, const wchar_t * src, size_t n)
404 {
405 size_t len_dst;
406 len_dst = wcslen (dst);
407 return wcsncpy (dst + len_dst, src, n);
408 }
409
410 #define SYS_IS_BIGENDIAN 0
411
412 #if SYS_IS_BIGENDIAN
413 #define _wcmcmp(a,b,len) memcmp((a),(b),(len) * sizeof (wchar_t))
414 #else // SYS_IS_BIGENDIAN
415 int
416 _wcmcmp (const wchar_t * str1, const wchar_t * str2, size_t len)
417 {
418 size_t i;
419 for (i = 0; i < len; i ++) {
420 if (str1[i] == str2[i]) {
421 continue;
422 } else if (str1[i] < str2[i]) {
423 return -1;
424 }
425 return 1;
426 }
427 return 0;
428 }
429 #endif // SYS_IS_BIGENDIAN
430
431 int
432 wcscmp (const wchar_t * str1, const wchar_t * str2)
433 {
434 int ret;
435 size_t len;
436 size_t len1;
437 size_t len2;
438 len1 = wcslen (str1);
439 len2 = wcslen (str2);
440 len = len1;
441 if (len > len2) {
442 len = len2;
443 }
444 ret = _wcmcmp (str1, str2, len);
445 if (0 == ret) {
446 if (len1 > len2) {
447 return -1;
448 } else if (len1 == len2) {
449 return 0;
450 }
451 return 1;
452 }
453 return ret;
454 }
455
456 int
457 wcsncmp (const wchar_t * str1, const wchar_t * str2, size_t n)
458 {
459 int ret;
460 size_t len;
461 size_t len1;
462 size_t len2;
463 len1 = wcslen (str1);
464 len2 = wcslen (str2);
465 len = len1;
466 if (len > len2) {
467 len = len2;
468 }
469 if (len > n) {
470 len = n;
471 }
472 ret = _wcmcmp (str1, str2, len);
473 if (0 == ret) {
474 if (len >= n) {
475 return 0;
476 }
477 if (len1 > len2) {
478 return -1;
479 } else if (len1 == len2) {
480 return 0;
481 }
482 return 1;
483 }
484 return ret;
485 }
486
487 wchar_t *
488 wcschr (const wchar_t * str, const wchar_t chr)
489 {
490 wchar_t * str2 = (wchar_t *)str;
491 size_t i;
492 size_t len;
493 len = wcslen (str2);
494 for (i = 0; i < len; i ++) {
495 if (str2[i] == chr) {
496 str2 += i;
497 return str2;
498 }
499 }
500 return NULL;
501 }
502
503 int wcscoll (const wchar_t *str1, const wchar_t * str2) {return wcscmp(str1, str2);}
504
505 //wcsxfrm: ¸ù¾Ýָ֨µĵØÓòÉèÖã̰Ñ×ַûԮstrSourceÖÐָ֨ÊýÁߵĿí×ַûתۻΪ
506 // ×ַûԮstrDest ,Èô³ɹ¦Ô򷵻ر»תۻ×ַûµijĶȣ̷ñÔ򷵻Ø-1
507 // ºÍstrxfrmگÊýÀàËÆ
508 size_t
509 wcsxfrm (wchar_t * str1, const wchar_t * str2, size_t n)
510 {
511 wcsncpy (str1, str2, n);
512 return wcslen (str1);
513 }
514
515 wchar_t *
516 wcsrchr (const wchar_t * str, wchar_t chr)
517 {
518 wchar_t * str2 = (wchar_t *)str;
519 ssize_t i;
520 i = wcslen (str2);
521 for (; i >= 0; i ++) {
522 if (str2[i] == chr) {
523 str2 += i;
524 return str2;
525 }
526 }
527 return NULL;
528 }
529
530 wchar_t *
531 wcspbrk (const wchar_t * str, const wchar_t * set)
532 {
533 wchar_t * str2 = (wchar_t *)str;
534 size_t i;
535 size_t j;
536 size_t len;
537 size_t len_set;
538 len = wcslen (str2);
539 len_set = wcslen (set);
540 for (i = 0; i < len; i ++) {
541 for (j = 0; j < len_set; j ++) {
542 if (str2[i] == set[j]) {
543 str2 += i;
544 return str2;
545 }
546 }
547 }
548 return NULL;
549 }
550
551 // ²éÕÒÔڼϺÏsetËùָ֨µÄÄÇЩ×ַûÔÚstrµĿªʼԦ³öÏֵÄ×î´ó¸öÊý
552 // Èçstr="13134abcde", set="1234567890", wcsspn(str,set)==5
553 // Èçstr="abcde", set="1234567890", wcsspn(str,set)==0
554 size_t
555 wcsspn (const wchar_t * str, const wchar_t * set)
556 {
557 size_t i;
558 size_t j;
559 size_t len;
560 size_t len_set;
561 len = wcslen (str);
562 len_set = wcslen (set);
563 for (i = 0; i < len; i ++) {
564 for (j = 0; j < len_set; j ++) {
565 if (str[i] == set[j]) {
566 break;
567 }
568 }
569 if (j >= len_set) {
570 return i;
571 }
572 }
573 return i;
574 }
575
576 // ²éÕÒÔڼϺÏsetËùָ֨µÄÄÇЩ×ַûÔÚstrµĿªʼԦһ³öÏֵÄ×î´ó¸öÊý
577 // Èçstr="13134abcde", set="1234567890", wcsspn(str,set)==0
578 // Èçstr="abcde123", set="1234567890", wcsspn(str,set)==5
579 size_t
580 wcscspn (const wchar_t * str, const wchar_t * set)
581 {
582 size_t i;
583 size_t j;
584 size_t len;
585 size_t len_set;
586 len = wcslen (str);
587 len_set = wcslen (set);
588 for (i = 0; i < len; i ++) {
589 for (j = 0; j < len_set; j ++) {
590 if (str[i] == set[j]) {
591 break;
592 }
593 }
594 if (j < len_set) {
595 return i;
596 }
597 }
598 return i;
599 }
600
601 wchar_t *
602 wcsstr (const wchar_t * str, const wchar_t * pat)
603 {
604 // TODO: improvement the alg for search
605 wchar_t *p;
606 p = wcschr (str, pat[0]);
607 for (; NULL != p;) {
608 if (0 == wcscmp (p, pat)) {
609 return p;
610 }
611 p = wcschr (p, pat[0]);
612 }
613 return NULL;
614 }
615
616 wchar_t *
617 wcstok (wchar_t * str, const wchar_t * set, wchar_t ** a)
618 {
619 wchar_t * p;
620 if (NULL == str) {
621 if (NULL == a) {
622 return NULL;
623 }
624 str = *a;
625 }
626 if (NULL == str) {
627 return NULL;
628 }
629 p = wcspbrk (str, set);
630 if (NULL == p) {
631 return NULL;
632 }
633 *p = 0;
634 *a = p;
635 return str;
636 }
637
638 #define iswblank iswspace
639 //#define ULONG_MAX INT_MAX
640 unsigned long
641 wcstoul (const wchar_t *nptr, wchar_t **endptr, int base)
642 {
643 int flg_overflow;
644 //int val_remain;
645 unsigned long val_ch;
646 unsigned long val_old;
647 unsigned long val;
648 /* check the base */
649 if ((1 == base) || (base > 36) || (base < 0)) {
650 // error
651 return 0;
652 }
653 // skip blank
654 while (iswblank (*nptr)) {nptr ++;}
655 if (0 == *nptr) {
656 return 0;
657 }
658 if (0 == base) {
659 // auto detect
660 switch (*nptr) {
661 case '0':
662 if (('x' == *(nptr + 1)) || ('X' == *(nptr + 1))) {
663 base = 16;
664 nptr += 2;
665 } else {
666 nptr += 1;
667 base = 8;
668 }
669 break;
670 case '1':
671 case '2':
672 case '3':
673 case '4':
674 case '5':
675 case '6':
676 case '7':
677 case '8':
678 case '9':
679 base = 10;
680 break;
681 }
682 } else {
683 if (16 == base) {
684 // detect if it has '0x' or '0X'
685 if (('0' == *nptr) && (('x' == *(nptr + 1)) || ('x' == *(nptr + 1)))) {
686 nptr += 2;
687 }
688 }
689 }
690 if (0 == base) {
691 // error
692 return 0;
693 }
694 val = 0;
695 val_old = 0;
696 flg_overflow = 0;
697 //val_remain = ULONG_MAX % base;
698 for (; '\0' != *nptr; nptr ++) {
699 val_ch = *nptr;
700 if (('0' <= val_ch) && (val_ch <= '9')) {
701 val_ch -= '0';
702 } else if (('a' <= val_ch) && (val_ch <= 'z')) {
703 val_ch = val_ch - 'a' + 10;
704 } else if (('A' <= val_ch) && (val_ch <= 'Z')) {
705 val_ch = val_ch - 'A' + 10;
706 } else {
707 // val_ch = base + 1;
708 break;
709 }
710 if (val_ch >= base) {
711 break;
712 }
713 if (flg_overflow) continue;
714 val_old = val;
715 val *= base;
716 val += val_ch;
717 if (val_old > val) {
718 flg_overflow = 1;
719 }
720 }
721 if (flg_overflow) {
722 val = ULONG_MAX;
723 }
724 if (0L != endptr) {
725 *endptr = (wchar_t *)nptr;
726 }
727 return val;
728 }
729
730 long
731 wcstol (const wchar_t * str, wchar_t ** end, int base)
732 {
733 int sign = 0;
734 unsigned long val0;
735 long val;
736 wchar_t ch;
737 // skip blank
738 for (; iswblank (*str); str ++) {
739 }
740 for (ch = *str; (ch == '-') || (ch == '+'); str ++) {
741 }
742 // the sign
743 if ('-' == ch) {
744 sign = 1;
745 str ++;
746 }
747 val0 = wcstoul (str, end, base);
748 if (val0 >= LONG_MAX) {
749 // overflow
750 val = LONG_MAX;
751 if (sign) {
752 val = LONG_MIN;
753 }
754 } else {
755 val = val0;
756 if (sign) {
757 val = -val0;
758 }
759 }
760 return val;
761 }
762
763 double
764 wcstod (const wchar_t * str, wchar_t ** end)
765 {
766 double val;
767 double mantissa;
768 unsigned long divisor;
769 unsigned long power;
770 int sign;
771 int sign_power;
772 wchar_t *pend;
773 wchar_t ch;
774 // skip blank
775 for (; iswblank (*str); str ++) {
776 }
777 for (ch = *str; (ch == '-') || (ch == '+'); str ++) {
778 }
779 // the sign
780 sign = 0;
781 if ('-' == ch) {
782 sign = 1;
783 str ++;
784 }
785 // skip leading zero
786 for (; '0' == (*str); str ++) {
787 }
788 val = 0.0;
789 mantissa = 0.0;
790 divisor = 0;
791 power = 0.0;
792 // integer part
793 for (ch = *str; ('0' <= ch) && (ch <= '9'); str ++) {
794 ch -= '0';
795 val *= 10;
796 val += ch;
797 }
798 // floating point & mantissa
799 if ('.' == *str) {
800 str ++;
801 for (ch = *str; ('0' <= ch) && (ch <= '9'); str ++) {
802 ch -= '0';
803 mantissa *= 10.0;
804 mantissa += ch;
805 divisor ++;
806 }
807 }
808 for (; divisor > 0; divisor --) {
809 mantissa /= 10.0;
810 }
811 val += mantissa;
812 sign_power = 0;
813 if (('e' == *str) || ('E' == *str)) {
814 str ++;
815 if ('-' == ch) {
816 sign_power = 1;
817 str ++;
818 }
819 pend = NULL;
820 power = wcstoul (str, &pend, 10);
821 if (NULL != pend) {
822 str = pend;
823 }
824 }
825 if (power > 0) {
826 if (sign_power) {
827 for (; power > 0; power --) {
828 val /= 10.0;
829 }
830 } else {
831 for (; power > 0; power --) {
832 val *= 10.0;
833 }
834 }
835 }
836 if (sign) {
837 val = - val;
838 }
839 if (end) {
840 *end = (wchar_t *)str;
841 }
842 return val;
843 }
844
845 char * setlocale (int category, const char *locale) {return NULL;}
846
847 int
848 eof (int fd)
849 {
850 return 0;
851 }
852
853 int
854 remove (const char *fn)
855 {
856 return svfs_filedelete (fn);
857 }
858
859 // access(): check access permissions of a file or pathname
860 // R_OK: read permission
861 // W_OK: write permission
862 // X_OK: execute/search permission
863 // F_OK: existence test
864 //All components of the pathname path are checked for access permissions (including F_OK)
865 int access(const char *path, int amode) {return amode;}
866
867 off_t lseek(int fildes, off_t offset, int whence) {return 0;}