diff --git a/library/changes b/library/changes index e5c65c6..d3371bd 100644 --- a/library/changes +++ b/library/changes @@ -16,6 +16,22 @@ - The startup code now references the linker symbol generated for the user-supplied main() function. +- log(+/-0), logb(+/-0), log10(+/-0) now return -infinity. + +- getcwd() now considers a buffer size of 0 an error, and it sets + the errno code to ERANGE if the buffer is too small. + +- With Unix path semantics enabled, rename() now fails if either + the old or the new name are empty strings. Same thing for + opendir(), utime(), unlink(), chown(), link(), readlink(), + realpath(), chdir(), access(), stat(), rmdir(), lstat(), + chmod(), statfs() and open()/fopen(). + +- Fixed several issues with the formatted output of strftime() + for the "C" locale: "%p" could return " PM", "%c" is now + equivalent to "%a %b %e %T %Y", "%x" is equivalent to "%m/%d/%y" + and "%X" is now equivalent to "%T". + c.lib 1.194 (15.7.2005) diff --git a/library/crt0.S b/library/crt0.S index 560d8f9..e8ae5c8 100644 --- a/library/crt0.S +++ b/library/crt0.S @@ -1,12 +1,12 @@ // -// $Id: crt0.S,v 1.4 2005-08-20 14:25:20 obarthel Exp $ +// $Id: crt0.S,v 1.5 2005-08-26 12:39:33 obarthel Exp $ // // :ts=4 // .text - .globl main + .globl main | This enforces linkage against the main() function .globl _main .globl _start diff --git a/library/dirent_opendir.c b/library/dirent_opendir.c index 5fb9f15..1d4f8fc 100644 --- a/library/dirent_opendir.c +++ b/library/dirent_opendir.c @@ -1,5 +1,5 @@ /* - * $Id: dirent_opendir.c,v 1.9 2005-03-18 12:38:22 obarthel Exp $ + * $Id: dirent_opendir.c,v 1.10 2005-08-26 12:39:33 obarthel Exp $ * * :ts=4 * @@ -128,6 +128,14 @@ opendir(const char * path_name) if(__unix_path_semantics) { + if(path_name[0] == '\0') + { + SHOWMSG("no name given"); + + __set_errno(ENOENT); + goto out; + } + if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) goto out; diff --git a/library/fcntl_open.c b/library/fcntl_open.c index 001623a..a32e806 100644 --- a/library/fcntl_open.c +++ b/library/fcntl_open.c @@ -1,5 +1,5 @@ /* - * $Id: fcntl_open.c,v 1.16 2005-04-24 08:46:37 obarthel Exp $ + * $Id: fcntl_open.c,v 1.17 2005-08-26 12:39:33 obarthel Exp $ * * :ts=4 * @@ -158,6 +158,14 @@ open(const char *path_name, int open_flag, ... /* mode_t mode */ ) { if(__unix_path_semantics) { + if(path_name[0] == '\0') + { + SHOWMSG("no name given"); + + __set_errno(ENOENT); + goto out; + } + if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) goto out; diff --git a/library/math_log.c b/library/math_log.c index 8a15222..e705e94 100644 --- a/library/math_log.c +++ b/library/math_log.c @@ -1,5 +1,5 @@ /* - * $Id: math_log.c,v 1.6 2005-02-25 10:14:21 obarthel Exp $ + * $Id: math_log.c,v 1.7 2005-08-26 12:39:33 obarthel Exp $ * * :ts=4 * @@ -252,8 +252,7 @@ log(double x) { __set_errno(ERANGE); - /* This should really be minus infinity. */ - result = (-__get_huge_val()); + result = -__inf(); } return(result); diff --git a/library/math_log10.c b/library/math_log10.c index 87014cf..361fb50 100644 --- a/library/math_log10.c +++ b/library/math_log10.c @@ -1,5 +1,5 @@ /* - * $Id: math_log10.c,v 1.5 2005-02-25 10:14:21 obarthel Exp $ + * $Id: math_log10.c,v 1.6 2005-08-26 12:39:33 obarthel Exp $ * * :ts=4 * @@ -194,8 +194,7 @@ log10(double x) { __set_errno(ERANGE); - /* This should really be minus infinity. */ - result = (-__get_huge_val()); + result = -__inf(); } return(result); diff --git a/library/math_logb.c b/library/math_logb.c index 23ee8d1..b5cc85b 100644 --- a/library/math_logb.c +++ b/library/math_logb.c @@ -1,5 +1,5 @@ /* - * $Id: math_logb.c,v 1.6 2005-05-08 08:51:29 obarthel Exp $ + * $Id: math_logb.c,v 1.7 2005-08-26 12:39:33 obarthel Exp $ * * :ts=4 * @@ -101,7 +101,7 @@ logb(double x) if(x == 0.0) { - result = -__get_huge_val(); + result = -__inf(); goto out; } diff --git a/library/mount_statfs.c b/library/mount_statfs.c index 522dd7f..14016a4 100644 --- a/library/mount_statfs.c +++ b/library/mount_statfs.c @@ -1,5 +1,5 @@ /* - * $Id: mount_statfs.c,v 1.5 2005-04-24 08:46:37 obarthel Exp $ + * $Id: mount_statfs.c,v 1.6 2005-08-26 12:39:33 obarthel Exp $ * * :ts=4 * @@ -84,6 +84,14 @@ statfs(const char *path, struct statfs *buf) { if(__unix_path_semantics) { + if(path[0] == '\0') + { + SHOWMSG("no name given"); + + __set_errno(ENOENT); + goto out; + } + if(__translate_unix_to_amiga_path_name(&path,&path_nti) != 0) goto out; diff --git a/library/ncrt0.S b/library/ncrt0.S index a0af290..6b25993 100644 --- a/library/ncrt0.S +++ b/library/ncrt0.S @@ -1,5 +1,5 @@ | -| $Id: ncrt0.S,v 1.3 2005-08-20 14:25:20 obarthel Exp $ +| $Id: ncrt0.S,v 1.4 2005-08-26 12:39:33 obarthel Exp $ | | :ts=4 | @@ -35,7 +35,7 @@ .text - .globl _main + .globl _main | This enforces linkage against the main() function .globl __main |----------------------------------------------------------------------------- diff --git a/library/nrcrt0.S b/library/nrcrt0.S index 50517e9..4cdbda5 100644 --- a/library/nrcrt0.S +++ b/library/nrcrt0.S @@ -1,5 +1,5 @@ | -| $Id: nrcrt0.S,v 1.3 2005-08-20 14:25:20 obarthel Exp $ +| $Id: nrcrt0.S,v 1.4 2005-08-26 12:39:33 obarthel Exp $ | | :ts=4 | @@ -56,7 +56,7 @@ MEMF_CLEAR = 65536 .text - .globl _main + .globl _main | This enforces linkage against the main() function .globl __main .globl ___is_resident diff --git a/library/stat_chmod.c b/library/stat_chmod.c index 684dc29..0549d8c 100644 --- a/library/stat_chmod.c +++ b/library/stat_chmod.c @@ -1,5 +1,5 @@ /* - * $Id: stat_chmod.c,v 1.6 2005-04-24 08:46:37 obarthel Exp $ + * $Id: stat_chmod.c,v 1.7 2005-08-26 12:39:33 obarthel Exp $ * * :ts=4 * @@ -83,6 +83,14 @@ chmod(const char * path_name, mode_t mode) { if(__unix_path_semantics) { + if(path_name[0] == '\0') + { + SHOWMSG("no name given"); + + __set_errno(ENOENT); + goto out; + } + if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) goto out; diff --git a/library/stat_lstat.c b/library/stat_lstat.c index 2a7f375..ee53236 100644 --- a/library/stat_lstat.c +++ b/library/stat_lstat.c @@ -1,5 +1,5 @@ /* - * $Id: stat_lstat.c,v 1.11 2005-06-21 15:01:08 tfrieden Exp $ + * $Id: stat_lstat.c,v 1.12 2005-08-26 12:39:33 obarthel Exp $ * * :ts=4 * @@ -206,6 +206,14 @@ lstat(const char * path_name, struct stat * st) { if(__unix_path_semantics) { + if(path_name[0] == '\0') + { + SHOWMSG("no name given"); + + __set_errno(ENOENT); + goto out; + } + if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) goto out; diff --git a/library/stat_rmdir.c b/library/stat_rmdir.c index cb0ff56..9cffd7d 100644 --- a/library/stat_rmdir.c +++ b/library/stat_rmdir.c @@ -1,5 +1,5 @@ /* - * $Id: stat_rmdir.c,v 1.6 2005-04-24 08:46:37 obarthel Exp $ + * $Id: stat_rmdir.c,v 1.7 2005-08-26 12:39:33 obarthel Exp $ * * :ts=4 * @@ -83,6 +83,14 @@ rmdir(const char * path_name) { if(__unix_path_semantics) { + if(path_name[0] == '\0') + { + SHOWMSG("no name given"); + + __set_errno(ENOENT); + goto out; + } + if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) goto out; diff --git a/library/stat_stat.c b/library/stat_stat.c index fb83c1b..0a40613 100644 --- a/library/stat_stat.c +++ b/library/stat_stat.c @@ -1,5 +1,5 @@ /* - * $Id: stat_stat.c,v 1.8 2005-04-24 08:46:37 obarthel Exp $ + * $Id: stat_stat.c,v 1.9 2005-08-26 12:39:33 obarthel Exp $ * * :ts=4 * @@ -93,6 +93,14 @@ stat(const char * path_name, struct stat * st) { if(__unix_path_semantics) { + if(path_name[0] == '\0') + { + SHOWMSG("no name given"); + + __set_errno(ENOENT); + goto out; + } + if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) goto out; diff --git a/library/stdio_rename.c b/library/stdio_rename.c index d359650..ca151d3 100644 --- a/library/stdio_rename.c +++ b/library/stdio_rename.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_rename.c,v 1.8 2005-04-24 09:53:12 obarthel Exp $ + * $Id: stdio_rename.c,v 1.9 2005-08-26 12:39:33 obarthel Exp $ * * :ts=4 * @@ -81,6 +81,14 @@ rename(const char *oldname,const char *newname) { if(__unix_path_semantics) { + if(oldname[0] == '\0' || newname[0] == '\0') + { + SHOWMSG("no name given"); + + __set_errno(ENOENT); + goto out; + } + if(__translate_unix_to_amiga_path_name(&oldname,&old_nti) != 0) goto out; diff --git a/library/time_strftime.c b/library/time_strftime.c index 92d44b8..37e2e94 100644 --- a/library/time_strftime.c +++ b/library/time_strftime.c @@ -1,5 +1,5 @@ /* - * $Id: time_strftime.c,v 1.16 2005-05-19 13:57:52 obarthel Exp $ + * $Id: time_strftime.c,v 1.17 2005-08-26 12:39:33 obarthel Exp $ * * :ts=4 * @@ -233,10 +233,10 @@ format_date(const char *format,const struct tm *tm,struct Hook * hook) store_string_via_hook(str,-1,hook); break; - /* Locale specific date and time ("%a %b %d %H:%M:%S %Y"). */ + /* Locale specific date and time ("%a %b %e %T %Y"). */ case 'c': - format_date("%a %b %d %H:%M:%S %Y",tm,hook); + format_date("%a %b %e %T %Y",tm,hook); break; /* The century number ("00"-"99"; C99). */ @@ -367,7 +367,7 @@ format_date(const char *format,const struct tm *tm,struct Hook * hook) assert( 0 <= tm->tm_hour && tm->tm_hour <= 23 ); - store_string_via_hook((tm->tm_hour < 12) ? "AM" :" PM",2,hook); + store_string_via_hook((tm->tm_hour < 12) ? "AM" : "PM",2,hook); break; /* 12 hour clock time (C99). */ @@ -451,16 +451,16 @@ format_date(const char *format,const struct tm *tm,struct Hook * hook) store_string_via_hook(buffer,2,hook); break; - /* Locale-specific date ("%a %b %d, %Y"). */ + /* Locale-specific date ("%m/%d/%y"). */ case 'x': - format_date("%a %b %d, %Y",tm,hook); + format_date("%m/%d/%y",tm,hook); break; - /* Locale-specific time ("%H:%M:%S"). */ + /* Locale-specific time ("%T"). */ case 'X': - format_date("%H:%M:%S",tm,hook); + format_date("%T",tm,hook); break; /* Year without century ("00"-"99"). */ diff --git a/library/unistd_access.c b/library/unistd_access.c index 82e9807..bb1f230 100644 --- a/library/unistd_access.c +++ b/library/unistd_access.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_access.c,v 1.6 2005-04-24 08:46:37 obarthel Exp $ + * $Id: unistd_access.c,v 1.7 2005-08-26 12:39:33 obarthel Exp $ * * :ts=4 * @@ -92,6 +92,14 @@ access(const char * path_name, int mode) if(__unix_path_semantics) { + if(path_name[0] == '\0') + { + SHOWMSG("no name given"); + + __set_errno(ENOENT); + goto out; + } + if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) goto out; diff --git a/library/unistd_chdir.c b/library/unistd_chdir.c index 18ad514..fa6429c 100644 --- a/library/unistd_chdir.c +++ b/library/unistd_chdir.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_chdir.c,v 1.7 2005-04-24 08:46:37 obarthel Exp $ + * $Id: unistd_chdir.c,v 1.8 2005-08-26 12:39:33 obarthel Exp $ * * :ts=4 * @@ -84,6 +84,14 @@ chdir(const char * path_name) { if(__unix_path_semantics) { + if(path_name[0] == '\0') + { + SHOWMSG("no name given"); + + __set_errno(ENOENT); + goto out; + } + if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) goto out; diff --git a/library/unistd_chown.c b/library/unistd_chown.c index 6e6dba4..af01ac7 100644 --- a/library/unistd_chown.c +++ b/library/unistd_chown.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_chown.c,v 1.7 2005-04-24 08:46:37 obarthel Exp $ + * $Id: unistd_chown.c,v 1.8 2005-08-26 12:39:33 obarthel Exp $ * * :ts=4 * @@ -92,6 +92,14 @@ chown(const char * path_name, uid_t owner, gid_t group) { if(__unix_path_semantics) { + if(path_name[0] == '\0') + { + SHOWMSG("no name given"); + + __set_errno(ENOENT); + goto out; + } + if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) goto out; diff --git a/library/unistd_getcwd.c b/library/unistd_getcwd.c index e70035e..96e56aa 100644 --- a/library/unistd_getcwd.c +++ b/library/unistd_getcwd.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_getcwd.c,v 1.8 2005-03-18 12:38:25 obarthel Exp $ + * $Id: unistd_getcwd.c,v 1.9 2005-08-26 12:39:33 obarthel Exp $ * * :ts=4 * @@ -77,14 +77,22 @@ __getcwd(char * buffer,size_t buffer_size,const char *file,int line) SHOWVALUE(buffer_size); assert( buffer != NULL ); - assert( (int)buffer_size >= 0 ); + assert( (int)buffer_size > 0 ); if(__check_abort_enabled) __check_abort(); + if(buffer_size == 0) + { + SHOWMSG("invalid buffer size"); + + __set_errno(EINVAL); + goto out; + } + #if defined(CHECK_FOR_NULL_POINTERS) { - if(buffer == NULL || buffer_size == 0) + if(buffer == NULL) { SHOWMSG("invalid buffer parameter"); @@ -111,10 +119,6 @@ __getcwd(char * buffer,size_t buffer_size,const char *file,int line) a custom buffer for the result to be returned. */ if(buffer == NULL) { - /* If the buffer size is not given, use the maximum we support. */ - if(buffer_size == 0) - buffer_size = MAXPATHLEN; - buffer_allocated = __malloc(buffer_size,file,line); if(buffer_allocated == NULL) { @@ -131,16 +135,15 @@ __getcwd(char * buffer,size_t buffer_size,const char *file,int line) { if(__current_path_name[0] != '\0') { - if(buffer_size == 0) + if(buffer_size < strlen(__current_path_name) + 1) { - __set_errno(ENOMEM); + SHOWMSG("buffer is too small"); + + __set_errno(ERANGE); goto out; } - assert( (int)buffer_size > 0 ); - - memmove(buffer,__current_path_name,buffer_size-1); - buffer[buffer_size-1] = '\0'; + strcpy(buffer,__current_path_name); D(("returning absolute path name '%s'",buffer)); @@ -159,9 +162,20 @@ __getcwd(char * buffer,size_t buffer_size,const char *file,int line) if(status == DOSFALSE) { + int errno_code; + LONG io_error; + SHOWMSG("could not get name from lock"); - __set_errno(__translate_io_error_to_errno(IoErr())); + io_error = IoErr(); + + /* Was the buffer too small? */ + if(io_error == ERROR_LINE_TOO_LONG) + errno_code = ERANGE; + else + errno_code = __translate_io_error_to_errno(io_error); + + __set_errno(errno_code); goto out; } @@ -172,23 +186,18 @@ __getcwd(char * buffer,size_t buffer_size,const char *file,int line) const char * path_name = buffer; size_t len; - if(buffer_size == 0) - { - __set_errno(ENOMEM); - goto out; - } - - assert( (int)buffer_size > 0 ); - if(__translate_amiga_to_unix_path_name(&path_name,&buffer_nti) != 0) goto out; - len = strlen(path_name); - if(len > buffer_size-1) - len = buffer_size-1; + if(buffer_size < strlen(path_name) + 1) + { + SHOWMSG("buffer is too small"); - memmove(buffer,path_name,len); - buffer[len] = '\0'; + __set_errno(ERANGE); + goto out; + } + + strcpy(buffer,path_name); } } #endif /* UNIX_PATH_SEMANTICS */ diff --git a/library/unistd_link.c b/library/unistd_link.c index bb2aa1a..a6f4483 100644 --- a/library/unistd_link.c +++ b/library/unistd_link.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_link.c,v 1.6 2005-04-24 08:46:37 obarthel Exp $ + * $Id: unistd_link.c,v 1.7 2005-08-26 12:39:33 obarthel Exp $ * * :ts=4 * @@ -84,6 +84,14 @@ link(const char * existing_path,const char * new_path) { if(__unix_path_semantics) { + if(existing_path[0] == '\0' || new_path[0] == '\0') + { + SHOWMSG("no name given"); + + __set_errno(ENOENT); + goto out; + } + if(__translate_unix_to_amiga_path_name(&existing_path,&existing_path_name_nti) != 0) goto out; diff --git a/library/unistd_readlink.c b/library/unistd_readlink.c index efa1d26..bfa2c69 100644 --- a/library/unistd_readlink.c +++ b/library/unistd_readlink.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_readlink.c,v 1.6 2005-04-24 08:46:37 obarthel Exp $ + * $Id: unistd_readlink.c,v 1.7 2005-08-26 12:39:33 obarthel Exp $ * * :ts=4 * @@ -83,8 +83,19 @@ readlink(const char * path_name, char * buffer, int buffer_size) #if defined(UNIX_PATH_SEMANTICS) { - if(__unix_path_semantics && __translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) - goto out; + if(__unix_path_semantics) + { + if(path_name[0] == '\0') + { + SHOWMSG("no name given"); + + __set_errno(ENOENT); + goto out; + } + + if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) + goto out; + } } #endif /* UNIX_PATH_SEMANTICS */ diff --git a/library/unistd_realpath.c b/library/unistd_realpath.c index bb2a3c1..477b30b 100644 --- a/library/unistd_realpath.c +++ b/library/unistd_realpath.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_realpath.c,v 1.5 2005-02-28 10:07:32 obarthel Exp $ + * $Id: unistd_realpath.c,v 1.6 2005-08-26 12:39:33 obarthel Exp $ * * :ts=4 * @@ -82,8 +82,19 @@ realpath(const char * path_name, char * buffer) #if defined(UNIX_PATH_SEMANTICS) { - if(__unix_path_semantics && __translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) - goto out; + if(__unix_path_semantics) + { + if(path_name[0] == '\0') + { + SHOWMSG("no name given"); + + __set_errno(ENOENT); + goto out; + } + + if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) + goto out; + } } #endif /* UNIX_PATH_SEMANTICS */ diff --git a/library/unistd_unlink.c b/library/unistd_unlink.c index 1d52168..12158b0 100644 --- a/library/unistd_unlink.c +++ b/library/unistd_unlink.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_unlink.c,v 1.8 2005-04-24 08:46:37 obarthel Exp $ + * $Id: unistd_unlink.c,v 1.9 2005-08-26 12:39:33 obarthel Exp $ * * :ts=4 * @@ -90,6 +90,14 @@ unlink(const char * path_name) { if(__unix_path_semantics) { + if(path_name[0] == '\0') + { + SHOWMSG("no name given"); + + __set_errno(ENOENT); + goto out; + } + if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) goto out; diff --git a/library/utime_utime.c b/library/utime_utime.c index b2fb7ab..fc23680 100644 --- a/library/utime_utime.c +++ b/library/utime_utime.c @@ -1,5 +1,5 @@ /* - * $Id: utime_utime.c,v 1.10 2005-04-24 08:46:37 obarthel Exp $ + * $Id: utime_utime.c,v 1.11 2005-08-26 12:39:33 obarthel Exp $ * * :ts=4 * @@ -93,6 +93,14 @@ utime(const char * path_name,const struct utimbuf * times) { if(__unix_path_semantics) { + if(path_name[0] == '\0') + { + SHOWMSG("no name given"); + + __set_errno(ENOENT); + goto out; + } + if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) goto out;