diff --git a/library/amiga_argarraydone.c b/library/amiga_argarraydone.c index 1531ec4..907b2b7 100644 --- a/library/amiga_argarraydone.c +++ b/library/amiga_argarraydone.c @@ -1,5 +1,5 @@ /* - * $Id: amiga_argarraydone.c,v 1.3 2006-01-08 12:04:22 obarthel Exp $ + * $Id: amiga_argarraydone.c,v 1.4 2006-09-25 14:05:31 obarthel Exp $ * * :ts=4 * @@ -48,7 +48,7 @@ /****************************************************************************/ -extern char **CXLIB_argarray; +extern const unsigned char **CXLIB_argarray; extern struct DiskObject * CXLIB_disko; diff --git a/library/changes b/library/changes index 5d989b6..bb21db7 100644 --- a/library/changes +++ b/library/changes @@ -5,6 +5,10 @@ - asctime_r() now returns NULL if the buffer is too short to hold even a single byte of data. +- ttyname() now calls ttyname_r(). Also, the libunix.a version of ttyname_r() + will produce "/CONSOLE" rather than "CONSOLE:". + + c.lib 1.201 (21.9.2006) - If defined, the local environment variable "DISABLE_COMMANDLINE_WILDCARD_EXPANSION" diff --git a/library/stdio_headers.h b/library/stdio_headers.h index 85a0784..947a08e 100644 --- a/library/stdio_headers.h +++ b/library/stdio_headers.h @@ -1,5 +1,5 @@ /* - * $Id: stdio_headers.h,v 1.26 2006-09-20 19:46:57 obarthel Exp $ + * $Id: stdio_headers.h,v 1.27 2006-09-25 14:05:31 obarthel Exp $ * * :ts=4 * @@ -433,7 +433,7 @@ extern int NOCOMMON __num_fd; /****************************************************************************/ -extern char * NOCOMMON __file_lock_semaphore_name; +extern const char * NOCOMMON __file_lock_semaphore_name; /****************************************************************************/ diff --git a/library/stdio_locksemaphorename.c b/library/stdio_locksemaphorename.c index 3952903..141a845 100644 --- a/library/stdio_locksemaphorename.c +++ b/library/stdio_locksemaphorename.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_locksemaphorename.c,v 1.5 2006-09-22 09:02:51 obarthel Exp $ + * $Id: stdio_locksemaphorename.c,v 1.6 2006-09-25 14:05:31 obarthel Exp $ * * :ts=4 * @@ -37,4 +37,4 @@ /****************************************************************************/ -char * NOCOMMON __file_lock_semaphore_name = (char *)"Advisory File Locking"; +const char * NOCOMMON __file_lock_semaphore_name = "Advisory File Locking"; diff --git a/library/unistd_ttyname.c b/library/unistd_ttyname.c index f128a43..8b54bff 100755 --- a/library/unistd_ttyname.c +++ b/library/unistd_ttyname.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_ttyname.c,v 1.4 2006-09-22 09:02:51 obarthel Exp $ + * $Id: unistd_ttyname.c,v 1.5 2006-09-25 14:05:31 obarthel Exp $ * * :ts=4 * @@ -44,106 +44,18 @@ char * ttyname(int file_descriptor) { + static char tty_file_name[_POSIX_TTY_NAME_MAX]; char * result = NULL; - BOOL is_tty = FALSE; - struct fd *fd; ENTER(); - SHOWVALUE(file_descriptor); - - __stdio_lock(); - - fd = __get_file_descriptor(file_descriptor); - if(fd == NULL) - { - __set_errno(EBADF); + if(ttyname_r(file_descriptor,tty_file_name,sizeof(tty_file_name)) != 0) goto out; - } - __fd_lock(fd); - - #if defined(__THREAD_SAFE) - { - if(FLAG_IS_SET(fd->fd_Flags,FDF_STDIO)) - { - BPTR file; - - switch(fd->fd_DefaultFile) - { - case STDIN_FILENO: - - file = Input(); - break; - - case STDOUT_FILENO: - - file = Output(); - break; - - case STDERR_FILENO: - - #if defined(__amigaos4__) - { - file = ErrorOutput(); - } - #else - { - struct Process * this_process = (struct Process *)FindTask(NULL); - - file = this_process->pr_CES; - } - #endif /* __amigaos4__ */ - - /* The following is rather controversial; if the standard error stream - is unavailable, we default to reuse the standard output stream. This - is problematic if the standard output stream was redirected and should - not be the same as the standard error output stream. */ - if(file == ZERO) - file = Output(); - - break; - - default: - - file = ZERO; - break; - } - - __fd_lock(fd); - - if(file != ZERO && IsInteractive(file)) - is_tty = TRUE; - - __fd_unlock(fd); - } - else - { - if(FLAG_IS_SET(fd->fd_Flags,FDF_IS_INTERACTIVE)) - is_tty = TRUE; - } - } - #else - { - if(FLAG_IS_SET(fd->fd_Flags,FDF_IS_INTERACTIVE)) - is_tty = TRUE; - } - #endif /* __THREAD_SAFE */ - - if(NOT is_tty) - { - __set_errno(ENOTTY); - goto out; - } - - result = (char *)"CONSOLE:"; + result = tty_file_name; out: - __fd_unlock(fd); - - __stdio_unlock(); - RETURN(result); return(result); } diff --git a/library/unistd_ttyname_r.c b/library/unistd_ttyname_r.c index 827c9b8..e50b191 100755 --- a/library/unistd_ttyname_r.c +++ b/library/unistd_ttyname_r.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_ttyname_r.c,v 1.3 2006-01-08 12:04:27 obarthel Exp $ + * $Id: unistd_ttyname_r.c,v 1.4 2006-09-25 14:05:31 obarthel Exp $ * * :ts=4 * @@ -44,6 +44,7 @@ int ttyname_r(int file_descriptor,char *name,size_t buflen) { + const char *tty_file_name; BOOL is_tty = FALSE; struct fd *fd; int result; @@ -136,13 +137,23 @@ ttyname_r(int file_descriptor,char *name,size_t buflen) goto out; } - if(buflen < _POSIX_TTY_NAME_MAX) /* XXX Should this be _POSIX_PATH_MAX? */ + #if defined(UNIX_PATH_SEMANTICS) + { + tty_file_name = "/CONSOLE"; + } + #else + { + tty_file_name = "CONSOLE:"; + } + #endif /* UNIX_PATH_SEMANTICS */ + + if(buflen < strlen(tty_file_name)+1) /* XXX Should this be _POSIX_PATH_MAX? */ { result = ERANGE; goto out; } - strcpy(name,"CONSOLE:"); /* The buffer is at least 9 bytes, so this is ok. */ + strcpy(name,tty_file_name); result = OK;