From 62cdaf7f99ccd0291c5cb053b4018ef3c023e6fc Mon Sep 17 00:00:00 2001 From: Boudewijn Dekker Date: Thu, 24 Jun 1999 21:59:41 +0000 Subject: [PATCH] no message svn path=/trunk/; revision=561 --- reactos/include/crtdll/internal/file.h | 2 + reactos/include/crtdll/mbstring.h | 5 ++ reactos/lib/crtdll/assert/assert.c | 5 +- reactos/lib/crtdll/conio/cscanf.c | 3 +- reactos/lib/crtdll/conio/kbhit.c | 2 +- reactos/lib/crtdll/direct/getdrive.c | 3 +- reactos/lib/crtdll/io/open.c | 7 +- reactos/lib/crtdll/locale/locale.c | 42 ++++++------ reactos/lib/crtdll/mbstring/mbsstr.c | 20 +++++- reactos/lib/crtdll/process/_system.c | 2 +- reactos/lib/crtdll/process/procid.c | 3 +- reactos/lib/crtdll/process/spawnve.c | 16 ++--- reactos/lib/crtdll/process/thread.c | 2 +- reactos/lib/crtdll/signal/signal.c | 92 ++++++++++++++++++++------ reactos/lib/crtdll/signal/xcptfil.c | 2 +- reactos/lib/crtdll/stdio/fscanf.c | 13 +--- reactos/lib/crtdll/stdio/popen.c | 2 +- reactos/lib/crtdll/stdio/vfprintf.c | 2 +- reactos/lib/crtdll/stdlib/abort.c | 11 ++- reactos/lib/crtdll/sys_stat/fstat.c | 24 +++++-- reactos/lib/crtdll/sys_stat/systime.c | 59 ++++++++++++++++- reactos/lib/crtdll/time/ctime.c | 3 + reactos/lib/crtdll/time/strdate.c | 18 ++++- reactos/lib/crtdll/time/strftime.c | 38 +++++++++-- reactos/lib/crtdll/time/strtime.c | 26 +++++++- 25 files changed, 303 insertions(+), 99 deletions(-) diff --git a/reactos/include/crtdll/internal/file.h b/reactos/include/crtdll/internal/file.h index d1b4c11c26a..b058381e171 100644 --- a/reactos/include/crtdll/internal/file.h +++ b/reactos/include/crtdll/internal/file.h @@ -55,6 +55,8 @@ int __fileno_dup2( int handle1, int handle2 ); int __fileno_setmode(int _fd, int _newmode); int __fileno_close(int _fd); +void sigabort_handler(int sig); + #include void UnixTimeToFileTime( time_t unix_time, FILETIME *filetime, DWORD remainder ); diff --git a/reactos/include/crtdll/mbstring.h b/reactos/include/crtdll/mbstring.h index 48b4f716d5f..47ba977e3a2 100644 --- a/reactos/include/crtdll/mbstring.h +++ b/reactos/include/crtdll/mbstring.h @@ -7,6 +7,11 @@ extern "C" { #include +size_t _mbstrlen(const char *str); + + + + int _mbbtype(unsigned char c, int type); int _mbsbtype( const unsigned char *str, size_t n ); diff --git a/reactos/lib/crtdll/assert/assert.c b/reactos/lib/crtdll/assert/assert.c index 1d70882e48b..2191a428028 100644 --- a/reactos/lib/crtdll/assert/assert.c +++ b/reactos/lib/crtdll/assert/assert.c @@ -2,12 +2,11 @@ #include #include #include +#include void _assert(const char *msg, const char *file, int line) { /* Assertion failed at foo.c line 45: x_file,&InputRecord,1,&NumberRead); return NumberRead; } diff --git a/reactos/lib/crtdll/direct/getdrive.c b/reactos/lib/crtdll/direct/getdrive.c index a0101adc853..97f674b2346 100644 --- a/reactos/lib/crtdll/direct/getdrive.c +++ b/reactos/lib/crtdll/direct/getdrive.c @@ -20,6 +20,7 @@ int _getdrive( void ) unsigned long _getdrives(void) { - return printf("get logical drives\n"); + //fixme get logical drives //return GetLogicalDrives(); + return 5; // drive A and C } \ No newline at end of file diff --git a/reactos/lib/crtdll/io/open.c b/reactos/lib/crtdll/io/open.c index c7fdcd7d96e..c3a8a6b2289 100644 --- a/reactos/lib/crtdll/io/open.c +++ b/reactos/lib/crtdll/io/open.c @@ -7,8 +7,13 @@ * UPDATE HISTORY: * 28/12/98: Created */ -#include + +// rember to interlock the allocation of fileno when making this thread safe + +// possibly store extra information at the handle + #include +#include #include #include #include diff --git a/reactos/lib/crtdll/locale/locale.c b/reactos/lib/crtdll/locale/locale.c index b5f7a7d6c4c..d72fcb09715 100644 --- a/reactos/lib/crtdll/locale/locale.c +++ b/reactos/lib/crtdll/locale/locale.c @@ -17,7 +17,7 @@ char *setlocale(int category, const char *locale) char code_page[100]; parse_locale((char *)locale,lang,country,code_page); - printf("%s %s %s %s\n",locale,lang,country,code_page); + //printf("%s %s %s %s\n",locale,lang,country,code_page); switch ( category ) @@ -115,26 +115,26 @@ const struct map_cntr { }; -struct lconv _lconv = { - '.', // decimal_point - ',', // thousands_sep - "", // grouping; - "DOL", // int_curr_symbol - "$", // currency_symbol - '.', // mon_decimal_point - ',', // mon_thousands_sep - "", // mon_grouping; - '+', // positive_sign - '-', // negative_sign - 2, // int_frac_digits - 2, // frac_digits - 1, // p_cs_precedes - 1, // p_sep_by_space - 1, // n_cs_precedes - 1, // n_sep_by_space - 1, // p_sign_posn; - 1 // n_sign_posn; - }; +struct lconv _lconv = { +".", // decimal_point +",", // thousands_sep +"", // grouping; +"DOL", // int_curr_symbol +"$", // currency_symbol +".", // mon_decimal_point +",", // mon_thousands_sep +"", // mon_grouping; +"+", // positive_sign +"-", // negative_sign +127, // int_frac_digits +127, // frac_digits +127, // p_cs_precedes +127, // p_sep_by_space +127, // n_cs_precedes +127, // n_sep_by_space +127, // p_sign_posn; +127 // n_sign_posn; +}; struct lconv *localeconv(void) { diff --git a/reactos/lib/crtdll/mbstring/mbsstr.c b/reactos/lib/crtdll/mbstring/mbsstr.c index 6bb56d72f82..bcc5b38c33a 100644 --- a/reactos/lib/crtdll/mbstring/mbsstr.c +++ b/reactos/lib/crtdll/mbstring/mbsstr.c @@ -1,4 +1,20 @@ -unsigned char * _mbsstr(const unsigned char *str1, const unsigned char *str2) +#include +#include + +unsigned char *_mbsstr(const unsigned char *src1,const unsigned char *src2) { - return strstr(str1,str2); + int len; + + if(src2 ==NULL || *src2 == 0) + return src1; + + len = _mbstrlen(src2); + + while(*src1) + { + if((*src1 == *src2) && (_mbsncmp(src1,src2,len) == 0)) + return(src1); + src1 = (unsigned char *)_mbsinc(src1); + } + return NULL; } \ No newline at end of file diff --git a/reactos/lib/crtdll/process/_system.c b/reactos/lib/crtdll/process/_system.c index 9f4dbc1c6fe..f6d5b674930 100644 --- a/reactos/lib/crtdll/process/_system.c +++ b/reactos/lib/crtdll/process/_system.c @@ -15,7 +15,7 @@ int system(const char *command) { char szCmdLine[MAX_PATH]; - char *szComSpec; + char *szComSpec=NULL; PROCESS_INFORMATION ProcessInformation; diff --git a/reactos/lib/crtdll/process/procid.c b/reactos/lib/crtdll/process/procid.c index 150b5439bbb..26e92cb09fe 100644 --- a/reactos/lib/crtdll/process/procid.c +++ b/reactos/lib/crtdll/process/procid.c @@ -3,7 +3,8 @@ int _getpid (void) { - printf("get current processid\n"); + //fixme GetCurrentProcessId //return (int)GetCurrentProcessId(); + return 1; } diff --git a/reactos/lib/crtdll/process/spawnve.c b/reactos/lib/crtdll/process/spawnve.c index 4917f8a4eac..7c1e1beeefe 100644 --- a/reactos/lib/crtdll/process/spawnve.c +++ b/reactos/lib/crtdll/process/spawnve.c @@ -83,17 +83,17 @@ static int go32_exec(const char *program, char **argv, char **envp) args[0] = 0; while(argv[i] != NULL ) { - strcat(args,envp[i]); - strcat(args," "); - i++; + strcat(args,envp[i]); + strcat(args," "); + i++; } - printf("%s \n %s\n",args, GetEnvironmentStrings()); + args[0] = 0; - i = 0; + i = 0; while(argv[i] != NULL ) { - strcat(args,argv[i]); - strcat(args," "); - i++; + strcat(args,argv[i]); + strcat(args," "); + i++; } return direct_exec_tail(program,args,envp); diff --git a/reactos/lib/crtdll/process/thread.c b/reactos/lib/crtdll/process/thread.c index 5578a8047ad..903fe2e59f1 100644 --- a/reactos/lib/crtdll/process/thread.c +++ b/reactos/lib/crtdll/process/thread.c @@ -22,7 +22,7 @@ unsigned long } void _endthread(void) { -printf("fixme ExitThread\n"); + //fixme ExitThread //ExitThread(0); for(;;); } \ No newline at end of file diff --git a/reactos/lib/crtdll/signal/signal.c b/reactos/lib/crtdll/signal/signal.c index affd626c9e6..2e221f42cae 100644 --- a/reactos/lib/crtdll/signal/signal.c +++ b/reactos/lib/crtdll/signal/signal.c @@ -1,59 +1,107 @@ -/* Copyright (C) 1994, 1995 Charles Sandmann (sandmann@clio.rice.edu) - Exception handling and basis for signal support for DJGPP V2.0 - This software may be freely distributed, no warranty. */ - #include #include +#include +#include +#include -//extern unsigned end __asm__ ("end"); +void _default_handler(int signal); -void __djgpp_traceback_exit(int); +typedef struct _sig_element +{ + int signal; + char *signame; + _p_sig_fn_t handler; +} sig_element; -static _p_sig_fn_t signal_list[SIGMAX]; /* SIG_DFL = 0 */ +static sig_element signal_list[SIGMAX] = + { + { 0, "Signal 0", SIG_DFL }, + { SIGABRT, "Aborted",SIG_DFL }, + { SIGFPE, "Erroneous arithmetic operation",SIG_DFL }, + { SIGILL, "Illegal instruction",SIG_DFL }, + { SIGINT, "Interrupt",SIG_DFL }, + { SIGSEGV, "Invalid access to storage",SIG_DFL }, + { SIGTERM, "Terminated",SIG_DFL }, + { SIGHUP, "Hangup",SIG_DFL }, + { SIGQUIT, "Quit",SIG_DFL }, + { SIGPIPE, "Broken pipe",SIG_DFL }, + { SIGKILL, "Killed",SIG_DFL }, + { SIGALRM, "Alarm clock",SIG_DFL }, + { 0, "Stopped (signal)",SIG_DFL }, + { 0, "Stopped",SIG_DFL }, + { 0, "Continued",SIG_DFL }, + { 0, "Child exited",SIG_DFL }, + { 0, "Stopped (tty input)",SIG_DFL }, + { 0, "Stopped (tty output)",SIG_DFL }, + { 0, NULL, SIG_DFL } + }; + +int nsignal = 21; _p_sig_fn_t signal(int sig, _p_sig_fn_t func) { _p_sig_fn_t temp; + int i; if(sig <= 0 || sig > SIGMAX || sig == SIGKILL) { - //errno = EINVAL; + __set_errno(EINVAL); return SIG_ERR; } - temp = signal_list[sig - 1]; - signal_list[sig - 1] = func; +// check with IsBadCodePtr + + if ( func < (_p_sig_fn_t)4096 ) { + __set_errno(EINVAL); + return SIG_ERR; + } + + for(i=0;i SIGMAX) return -1; - temp = signal_list[sig - 1]; + for(i=0;i (_p_sig_fn_t)&end) - { - // err("Bad signal handler, "); - __djgpp_traceback_exit(sig); /* does not return */ - } + _default_handler(sig); /* this does not return */ else temp(sig); -#endif return 0; } -void __djgpp_traceback_exit(int sig) + + +void _default_handler(int sig) { _exit(3); } + + diff --git a/reactos/lib/crtdll/signal/xcptfil.c b/reactos/lib/crtdll/signal/xcptfil.c index 3ab79f1aad6..3028e9a9538 100644 --- a/reactos/lib/crtdll/signal/xcptfil.c +++ b/reactos/lib/crtdll/signal/xcptfil.c @@ -6,6 +6,6 @@ int _XcptFilter ( struct _EXCEPTION_POINTERS * ExceptionInfo ) { - return printf("Unhandled exception info\n"); + //fixme XcptFilter // return UnhandledExceptionFilter(ExceptionInfo); } \ No newline at end of file diff --git a/reactos/lib/crtdll/stdio/fscanf.c b/reactos/lib/crtdll/stdio/fscanf.c index 4e7c893d30d..f8f33e7e99c 100644 --- a/reactos/lib/crtdll/stdio/fscanf.c +++ b/reactos/lib/crtdll/stdio/fscanf.c @@ -22,14 +22,6 @@ Cambridge, MA 02139, USA. */ #include #include -#if 0 - -int fscanf(FILE *stream,const char *format, ...) -{ -} - - -#else int __vfscanf (FILE *s, const char *format, va_list argptr); /* Read formatted input from STREAM according to the format string FORMAT. */ @@ -54,7 +46,7 @@ fwscanf(FILE *stream, const wchar_t *fmt, ...) char *cf; int i,len = wcslen(fmt); - cf = alloca(len+1); + cf = malloc(len+1); for(i=0;i 0) putc( ' ',f); continue; - + case 'S': case 'w': sw = va_arg(args,short int *); // DPRINT("L %x\n",sw); diff --git a/reactos/lib/crtdll/stdlib/abort.c b/reactos/lib/crtdll/stdlib/abort.c index 18c1e582a57..3c33587b678 100644 --- a/reactos/lib/crtdll/stdlib/abort.c +++ b/reactos/lib/crtdll/stdlib/abort.c @@ -1,11 +1,16 @@ #include #include #include +#include -static char msg[] = "Abort!\r\n"; +char *msg ="Abort\n\r"; void abort() { - _write(stderr->_file, msg, sizeof(msg)-1); - _exit(1); + fflush(NULL); + fcloseall(); + raise(SIGABRT); + _write(stderr->_file, msg, sizeof(msg)-1); + exit(3); } + diff --git a/reactos/lib/crtdll/sys_stat/fstat.c b/reactos/lib/crtdll/sys_stat/fstat.c index 7c008e65630..458e31bb260 100644 --- a/reactos/lib/crtdll/sys_stat/fstat.c +++ b/reactos/lib/crtdll/sys_stat/fstat.c @@ -1,8 +1,18 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/sys/fstat.c + * PURPOSE: Gather file information + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 28/12/98: Created + */ +#include #include #include #include #include -#include +#include #include @@ -14,15 +24,17 @@ _fstat(int fd, struct stat *statbuf) if (!statbuf) { - + __set_errno(EINVAL); return -1; } - if ( !GetFileInformationByHandle(_get_osfhandle(fd),&FileInformation) ) + if ( !GetFileInformationByHandle(_get_osfhandle(fd),&FileInformation) ) { + __set_errno (EBADF); return -1; -// statbuf->st_ctime = FileTimeToUnixTime( &FileInformation.ftCreationTime,NULL); -// statbuf->st_atime = FileTimeToUnixTime( &FileInformation.ftLastAccessTime,NULL); -// statbuf->st_mtime = FileTimeToUnixTime( &FileInformation.ftLastWriteTime,NULL); + } + statbuf->st_ctime = FileTimeToUnixTime( &FileInformation.ftCreationTime,NULL); + statbuf->st_atime = FileTimeToUnixTime( &FileInformation.ftLastAccessTime,NULL); + statbuf->st_mtime = FileTimeToUnixTime( &FileInformation.ftLastWriteTime,NULL); statbuf->st_dev = fd; statbuf->st_size = FileInformation.nFileSizeLow; diff --git a/reactos/lib/crtdll/sys_stat/systime.c b/reactos/lib/crtdll/sys_stat/systime.c index 76859f501c4..466451f5603 100644 --- a/reactos/lib/crtdll/sys_stat/systime.c +++ b/reactos/lib/crtdll/sys_stat/systime.c @@ -1,14 +1,67 @@ +#include #include + +int month[12] = { 31,28,31,30,31,30,31,31,30,31,30,31}; unsigned int _getsystime(struct tm *tp) { - printf("getsystime\n"); - return 0; + SYSTEMTIME Time; + TIME_ZONE_INFORMATION TimeZoneInformation; + DWORD TimeZoneId; + int i; + + GetLocalTime(&Time); + + tp->tm_year = Time.wYear - 1900; + tp->tm_mon = Time.wMonth - 1; + tp->tm_wday = Time.wDayOfWeek; + tp->tm_mday = Time.wDay; + tp->tm_hour = Time.wHour; + tp->tm_min = Time.wMinute; + tp->tm_sec = Time.wSecond; + + tp->tm_isdst = -1; + + //FIXME GetTimeZoneInformation currently not in kernel32 + + //TimeZoneId = GetTimeZoneInformation(&TimeZoneInformation ); + //if ( TimeZoneId == TIME_ZONE_ID_DAYLIGHT ) { + // tp->tm_isdst = 1; + //} + //else + // tp->tm_isdst = 0; + + + + if ( tp->tm_year%4 == 0 ) { + if (tp->tm_year%100 != 0 ) + tp->tm_yday = 1; + else if ( (tp->tm_year-100)%1000 == 0 ) + tp->tm_yday = 1; + } + + for(i=0;i<=tp->tm_mon;i++) + tp->tm_yday += month[i]; + + return Time.wMilliseconds; } unsigned int _setsystime(struct tm *tp, unsigned int ms) { - printf("setsystime\n"); + SYSTEMTIME Time; + + Time.wYear = tp->tm_year + 1900; + Time.wMonth = tp->tm_mon + 1; + Time.wDayOfWeek = tp->tm_wday; + Time.wDay = tp->tm_mday; + Time.wHour = tp->tm_hour; + Time.wMinute = tp->tm_min; + Time.wSecond = tp->tm_sec; + Time.wMilliseconds = ms; + + if ( !SetLocalTime(&Time)) + return -1; + return 0; } \ No newline at end of file diff --git a/reactos/lib/crtdll/time/ctime.c b/reactos/lib/crtdll/time/ctime.c index a9f3e78b2f9..9f33c97ebe1 100644 --- a/reactos/lib/crtdll/time/ctime.c +++ b/reactos/lib/crtdll/time/ctime.c @@ -1,3 +1,6 @@ + +// fix djdir + /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ /* This file has been modified by DJ Delorie. These modifications are ** Copyright (C) 1995 DJ Delorie, 24 Kirsten Ave, Rochester NH, diff --git a/reactos/lib/crtdll/time/strdate.c b/reactos/lib/crtdll/time/strdate.c index 253bfc0178f..b9b25657bcb 100644 --- a/reactos/lib/crtdll/time/strdate.c +++ b/reactos/lib/crtdll/time/strdate.c @@ -1,7 +1,17 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/time/strtime.c + * PURPOSE: Fills a buffer with a formatted date representation + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 28/12/98: Created + */ #include #include +#include +#include -// copy date according to mm/dd/yy format char *_strdate( const char *datestr ) { @@ -9,10 +19,12 @@ char *_strdate( const char *datestr ) struct tm *d; char *dt = (char *)datestr; - if ( datestr == NULL ) + if ( datestr == NULL ){ + __set_errno(EINVAL); return NULL; + } t = time(NULL); d = localtime(&t); - sprintf(dt,"%d\%d\%d",d->tm_mday,d->tm_mon+1,d->tm_year); + sprintf(dt,"%d/%d/%d",d->tm_mday,d->tm_mon+1,d->tm_year); return dt; } \ No newline at end of file diff --git a/reactos/lib/crtdll/time/strftime.c b/reactos/lib/crtdll/time/strftime.c index 94f18d25835..243fe90f114 100644 --- a/reactos/lib/crtdll/time/strftime.c +++ b/reactos/lib/crtdll/time/strftime.c @@ -1,8 +1,8 @@ /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ #include - - #include +#include +#include #define TM_YEAR_BASE 1900 @@ -55,7 +55,9 @@ _fmt(const char *format, const struct tm *t) { for (; *format; ++format) { - if (*format == '%') + if (*format == '%') { + if (*(format+1) == '#' ) {format++;} + switch(*++format) { case '\0': @@ -206,6 +208,7 @@ _fmt(const char *format, const struct tm *t) default: break; } + } if (!gsize--) return 0; *pt++ = *format; @@ -230,5 +233,32 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *t) size_t wcsftime(wchar_t *s, size_t maxsize, const wchar_t *format, const struct tm *t) { - printf("wcsftime\n"); + char *x; + char *f; + int i,j; + x = malloc(maxsize); + j = wcslen(format); + f = malloc(j+1); + for(i=0;i +#include +#include +#include char *_strtime(char* buf) { - printf("strtime\n"); - return ""; + time_t t; + struct tm *d; + char *dt = (char *)buf; + + if ( buf == NULL ) { + __set_errno(EINVAL); + return NULL; + } + t = time(NULL); + d = localtime(&t); + sprintf(dt,"%d:%d:%d",d->tm_hour,d->tm_min,d->tm_sec); + return dt; } \ No newline at end of file