1
0
mirror of https://github.com/adtools/clib2.git synced 2025-12-08 14:59:05 +00:00

- 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".


git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@15020 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
Olaf Barthel
2005-08-26 12:39:33 +00:00
parent 5acfef419b
commit 6612118e97
25 changed files with 226 additions and 69 deletions

View File

@@ -16,6 +16,22 @@
- The startup code now references the linker symbol generated for - The startup code now references the linker symbol generated for
the user-supplied main() function. 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) c.lib 1.194 (15.7.2005)

View File

@@ -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 // :ts=4
// //
.text .text
.globl main .globl main | This enforces linkage against the main() function
.globl _main .globl _main
.globl _start .globl _start

View File

@@ -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 * :ts=4
* *
@@ -128,6 +128,14 @@ opendir(const char * path_name)
if(__unix_path_semantics) 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) if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0)
goto out; goto out;

View File

@@ -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 * :ts=4
* *
@@ -158,6 +158,14 @@ open(const char *path_name, int open_flag, ... /* mode_t mode */ )
{ {
if(__unix_path_semantics) 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) if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0)
goto out; goto out;

View File

@@ -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 * :ts=4
* *
@@ -252,8 +252,7 @@ log(double x)
{ {
__set_errno(ERANGE); __set_errno(ERANGE);
/* This should really be minus infinity. */ result = -__inf();
result = (-__get_huge_val());
} }
return(result); return(result);

View File

@@ -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 * :ts=4
* *
@@ -194,8 +194,7 @@ log10(double x)
{ {
__set_errno(ERANGE); __set_errno(ERANGE);
/* This should really be minus infinity. */ result = -__inf();
result = (-__get_huge_val());
} }
return(result); return(result);

View File

@@ -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 * :ts=4
* *
@@ -101,7 +101,7 @@ logb(double x)
if(x == 0.0) if(x == 0.0)
{ {
result = -__get_huge_val(); result = -__inf();
goto out; goto out;
} }

View File

@@ -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 * :ts=4
* *
@@ -84,6 +84,14 @@ statfs(const char *path, struct statfs *buf)
{ {
if(__unix_path_semantics) 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) if(__translate_unix_to_amiga_path_name(&path,&path_nti) != 0)
goto out; goto out;

View File

@@ -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 | :ts=4
| |
@@ -35,7 +35,7 @@
.text .text
.globl _main .globl _main | This enforces linkage against the main() function
.globl __main .globl __main
|----------------------------------------------------------------------------- |-----------------------------------------------------------------------------

View File

@@ -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 | :ts=4
| |
@@ -56,7 +56,7 @@ MEMF_CLEAR = 65536
.text .text
.globl _main .globl _main | This enforces linkage against the main() function
.globl __main .globl __main
.globl ___is_resident .globl ___is_resident

View File

@@ -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 * :ts=4
* *
@@ -83,6 +83,14 @@ chmod(const char * path_name, mode_t mode)
{ {
if(__unix_path_semantics) 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) if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0)
goto out; goto out;

View File

@@ -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 * :ts=4
* *
@@ -206,6 +206,14 @@ lstat(const char * path_name, struct stat * st)
{ {
if(__unix_path_semantics) 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) if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0)
goto out; goto out;

View File

@@ -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 * :ts=4
* *
@@ -83,6 +83,14 @@ rmdir(const char * path_name)
{ {
if(__unix_path_semantics) 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) if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0)
goto out; goto out;

View File

@@ -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 * :ts=4
* *
@@ -93,6 +93,14 @@ stat(const char * path_name, struct stat * st)
{ {
if(__unix_path_semantics) 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) if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0)
goto out; goto out;

View File

@@ -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 * :ts=4
* *
@@ -81,6 +81,14 @@ rename(const char *oldname,const char *newname)
{ {
if(__unix_path_semantics) 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) if(__translate_unix_to_amiga_path_name(&oldname,&old_nti) != 0)
goto out; goto out;

View File

@@ -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 * :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); store_string_via_hook(str,-1,hook);
break; 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': case 'c':
format_date("%a %b %d %H:%M:%S %Y",tm,hook); format_date("%a %b %e %T %Y",tm,hook);
break; break;
/* The century number ("00"-"99"; C99). */ /* 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 ); 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; break;
/* 12 hour clock time (C99). */ /* 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); store_string_via_hook(buffer,2,hook);
break; break;
/* Locale-specific date ("%a %b %d, %Y"). */ /* Locale-specific date ("%m/%d/%y"). */
case 'x': case 'x':
format_date("%a %b %d, %Y",tm,hook); format_date("%m/%d/%y",tm,hook);
break; break;
/* Locale-specific time ("%H:%M:%S"). */ /* Locale-specific time ("%T"). */
case 'X': case 'X':
format_date("%H:%M:%S",tm,hook); format_date("%T",tm,hook);
break; break;
/* Year without century ("00"-"99"). */ /* Year without century ("00"-"99"). */

View File

@@ -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 * :ts=4
* *
@@ -92,6 +92,14 @@ access(const char * path_name, int mode)
if(__unix_path_semantics) 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) if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0)
goto out; goto out;

View File

@@ -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 * :ts=4
* *
@@ -84,6 +84,14 @@ chdir(const char * path_name)
{ {
if(__unix_path_semantics) 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) if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0)
goto out; goto out;

View File

@@ -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 * :ts=4
* *
@@ -92,6 +92,14 @@ chown(const char * path_name, uid_t owner, gid_t group)
{ {
if(__unix_path_semantics) 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) if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0)
goto out; goto out;

View File

@@ -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 * :ts=4
* *
@@ -77,14 +77,22 @@ __getcwd(char * buffer,size_t buffer_size,const char *file,int line)
SHOWVALUE(buffer_size); SHOWVALUE(buffer_size);
assert( buffer != NULL ); assert( buffer != NULL );
assert( (int)buffer_size >= 0 ); assert( (int)buffer_size > 0 );
if(__check_abort_enabled) if(__check_abort_enabled)
__check_abort(); __check_abort();
if(buffer_size == 0)
{
SHOWMSG("invalid buffer size");
__set_errno(EINVAL);
goto out;
}
#if defined(CHECK_FOR_NULL_POINTERS) #if defined(CHECK_FOR_NULL_POINTERS)
{ {
if(buffer == NULL || buffer_size == 0) if(buffer == NULL)
{ {
SHOWMSG("invalid buffer parameter"); 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. */ a custom buffer for the result to be returned. */
if(buffer == NULL) 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); buffer_allocated = __malloc(buffer_size,file,line);
if(buffer_allocated == NULL) 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(__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; goto out;
} }
assert( (int)buffer_size > 0 ); strcpy(buffer,__current_path_name);
memmove(buffer,__current_path_name,buffer_size-1);
buffer[buffer_size-1] = '\0';
D(("returning absolute path name '%s'",buffer)); 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) if(status == DOSFALSE)
{ {
int errno_code;
LONG io_error;
SHOWMSG("could not get name from lock"); 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; goto out;
} }
@@ -172,23 +186,18 @@ __getcwd(char * buffer,size_t buffer_size,const char *file,int line)
const char * path_name = buffer; const char * path_name = buffer;
size_t len; 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) if(__translate_amiga_to_unix_path_name(&path_name,&buffer_nti) != 0)
goto out; goto out;
len = strlen(path_name); if(buffer_size < strlen(path_name) + 1)
if(len > buffer_size-1) {
len = buffer_size-1; SHOWMSG("buffer is too small");
memmove(buffer,path_name,len); __set_errno(ERANGE);
buffer[len] = '\0'; goto out;
}
strcpy(buffer,path_name);
} }
} }
#endif /* UNIX_PATH_SEMANTICS */ #endif /* UNIX_PATH_SEMANTICS */

View File

@@ -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 * :ts=4
* *
@@ -84,6 +84,14 @@ link(const char * existing_path,const char * new_path)
{ {
if(__unix_path_semantics) 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) if(__translate_unix_to_amiga_path_name(&existing_path,&existing_path_name_nti) != 0)
goto out; goto out;

View File

@@ -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 * :ts=4
* *
@@ -83,9 +83,20 @@ readlink(const char * path_name, char * buffer, int buffer_size)
#if defined(UNIX_PATH_SEMANTICS) #if defined(UNIX_PATH_SEMANTICS)
{ {
if(__unix_path_semantics && __translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) if(__unix_path_semantics)
{
if(path_name[0] == '\0')
{
SHOWMSG("no name given");
__set_errno(ENOENT);
goto out; goto out;
} }
if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0)
goto out;
}
}
#endif /* UNIX_PATH_SEMANTICS */ #endif /* UNIX_PATH_SEMANTICS */
D(("trying to get a lock on '%s'",path_name)); D(("trying to get a lock on '%s'",path_name));

View File

@@ -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 * :ts=4
* *
@@ -82,9 +82,20 @@ realpath(const char * path_name, char * buffer)
#if defined(UNIX_PATH_SEMANTICS) #if defined(UNIX_PATH_SEMANTICS)
{ {
if(__unix_path_semantics && __translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) if(__unix_path_semantics)
{
if(path_name[0] == '\0')
{
SHOWMSG("no name given");
__set_errno(ENOENT);
goto out; goto out;
} }
if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0)
goto out;
}
}
#endif /* UNIX_PATH_SEMANTICS */ #endif /* UNIX_PATH_SEMANTICS */
D(("trying to get a lock on '%s'",path_name)); D(("trying to get a lock on '%s'",path_name));

View File

@@ -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 * :ts=4
* *
@@ -90,6 +90,14 @@ unlink(const char * path_name)
{ {
if(__unix_path_semantics) 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) if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0)
goto out; goto out;

View File

@@ -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 * :ts=4
* *
@@ -93,6 +93,14 @@ utime(const char * path_name,const struct utimbuf * times)
{ {
if(__unix_path_semantics) 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) if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0)
goto out; goto out;