Bugzilla bug 276330: add a new configuration macro _PR_HAVE_O_APPEND, NSPRPUB_PRE_4_2_CLIENT_BRANCH
authorwtchang%redhat.com
Mon, 17 Jan 2005 22:13:36 +0000
branchNSPRPUB_PRE_4_2_CLIENT_BRANCH
changeset 3249 e0913ff753d9cf91c395886ff33f9c39d8034199
parent 3247 3cfe0e2ba672e74e6396b87d004009afc2d6d3e0
child 3250 1aa68bd7cf1426f115081dc6acccda31ca863e73
push idunknown
push userunknown
push dateunknown
bugs276330
Bugzilla bug 276330: add a new configuration macro _PR_HAVE_O_APPEND, which should be defined on platforms (e.g., Unix and BeOS) that have O_APPEND or its equivalent. The patch is contributed by tqh <thesuckiestemail@yahoo.se>. r=wtc,sergei_d. Modified files: _beos.h _unixos.h primpl.h prfile.c Tag: NSPRPUB_PRE_4_2_CLIENT_BRANCH
pr/include/md/_beos.h
pr/include/md/_unixos.h
pr/include/private/primpl.h
pr/src/io/prfile.c
--- a/pr/include/md/_beos.h
+++ b/pr/include/md/_beos.h
@@ -90,16 +90,17 @@
 #define HAVE_CVAR_BUILT_ON_SEM
 #define _PR_GLOBAL_THREADS_ONLY
 #define _PR_BTHREADS
 #define _PR_NEED_FAKE_POLL
 #define _PR_HAVE_PEEK_BUFFER
 #define _PR_PEEK_BUFFER_MAX (16 * 1024)
 #define _PR_FD_NEED_EMULATE_MSG_PEEK(fd) 1
 #define _PR_CONNECT_DOES_NOT_BIND
+#define _PR_HAVE_O_APPEND
 
 /* Define threading functions and objects as native BeOS */
 struct _MDThread {
     thread_id	tid;	/* BeOS thread handle */
 	sem_id		joinSem;	/* sems used to synchronzie joining */
 	PRBool	is_joining;	/* TRUE if someone is currently waiting to
 						   join this thread */
 };
--- a/pr/include/md/_unixos.h
+++ b/pr/include/md/_unixos.h
@@ -74,16 +74,18 @@
  * <sys/types.h>, so we include it explicitly.
  */
 #include <sys/time.h>
 #include <sys/types.h>
 #if defined(AIX)  /* Only pre-4.2 AIX needs it, but for simplicity... */
 #include <sys/select.h>
 #endif
 
+#define _PR_HAVE_O_APPEND
+
 #define PR_DIRECTORY_SEPARATOR		'/'
 #define PR_DIRECTORY_SEPARATOR_STR	"/"
 #define PR_PATH_SEPARATOR		':'
 #define PR_PATH_SEPARATOR_STR		":"
 #define GCPTR
 typedef int (*FARPROC)();
 
 /*
--- a/pr/include/private/primpl.h
+++ b/pr/include/private/primpl.h
@@ -1733,18 +1733,21 @@ struct PRFilePrivate {
     PRIntn lockCount;   /*   0: not locked
                          *  -1: a native lockfile call is in progress
                          * > 0: # times the file is locked */
 #ifdef _PR_HAVE_PEEK_BUFFER
     char *peekBuffer;
     PRInt32 peekBufSize;
     PRInt32 peekBytes;
 #endif
-#if !defined(XP_UNIX)   /* BugZilla: 4090 */
-    PRBool  appendMode;                             
+#if !defined(_PR_HAVE_O_APPEND)
+    PRBool  appendMode; /* Some platforms don't have O_APPEND or its
+                         * equivalent, so they have to seek to end of
+                         * file on write if the file was opened in
+                         * append mode.  See Bugzilla 4090, 276330. */
 #endif
     _MDFileDesc md;
 #ifdef _PR_STRICT_ADDR_LEN
     PRUint16 af;        /* If the platform requires passing the exact
                          * length of the sockaddr structure for the
                          * address family of the socket to socket
                          * functions like accept(), we need to save
                          * the address family of the socket. */
--- a/pr/src/io/prfile.c
+++ b/pr/src/io/prfile.c
@@ -93,24 +93,24 @@ static PRInt32 PR_CALLBACK FileWrite(PRF
     if (_PR_IO_PENDING(me)) {
         PR_SetError(PR_IO_PENDING_ERROR, 0);
 	    rv = -1;
     }
     if (rv != 0)
     	return rv;
 
     count = 0;
-#if !defined(XP_UNIX)  /* BugZilla: 4090 */
+#if !defined(_PR_HAVE_O_APPEND)  /* Bugzilla: 4090, 276330 */
     if ( PR_TRUE == fd->secret->appendMode ) {
         rv = PR_Seek(fd, 0, PR_SEEK_END );
         if ( -1 == rv )  {
             return rv;
         }
     } /* if (fd->secret->appendMode...) */
-#endif /* XP_UNIX */
+#endif /* _PR_HAVE_O_APPEND */
     while (amount > 0) {
 		temp = _PR_MD_WRITE(fd, buf, amount);
 		if (temp < 0) {
 			count = -1;
 			break;
 		}
 		count += temp;
 		if (fd->secret->nonblocking) {
@@ -356,59 +356,59 @@ PR_IMPLEMENT(const PRIOMethods*) PR_GetP
 {
     return &_pr_pipeMethods;
 }
 
 PR_IMPLEMENT(PRFileDesc*) PR_Open(const char *name, PRIntn flags, PRIntn mode)
 {
     PRInt32 osfd;
     PRFileDesc *fd = 0;
-#if !defined(XP_UNIX) /* BugZilla: 4090 */
+#if !defined(_PR_HAVE_O_APPEND)
     PRBool  appendMode = ( PR_APPEND & flags )? PR_TRUE : PR_FALSE;
 #endif
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
 
     /* Map pr open flags and mode to os specific flags */
 
     osfd = _PR_MD_OPEN(name, flags, mode);
     if (osfd != -1) {
         fd = PR_AllocFileDesc(osfd, &_pr_fileMethods);
         if (!fd) {
             (void) _PR_MD_CLOSE_FILE(osfd);
         } else {
-#if !defined(XP_UNIX) /* BugZilla: 4090 */
+#if !defined(_PR_HAVE_O_APPEND)
             fd->secret->appendMode = appendMode;
 #endif
             _PR_MD_INIT_FD_INHERITABLE(fd, PR_FALSE);
         }
     }
     return fd;
 }
 
 PR_IMPLEMENT(PRFileDesc*) PR_OpenFile(
     const char *name, PRIntn flags, PRIntn mode)
 {
     PRInt32 osfd;
     PRFileDesc *fd = 0;
-#if !defined(XP_UNIX) /* BugZilla: 4090 */
+#if !defined(_PR_HAVE_O_APPEND)
     PRBool  appendMode = ( PR_APPEND & flags )? PR_TRUE : PR_FALSE;
 #endif
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
 
     /* Map pr open flags and mode to os specific flags */
 
     osfd = _PR_MD_OPEN_FILE(name, flags, mode);
     if (osfd != -1) {
         fd = PR_AllocFileDesc(osfd, &_pr_fileMethods);
         if (!fd) {
             (void) _PR_MD_CLOSE_FILE(osfd);
         } else {
-#if !defined(XP_UNIX) /* BugZilla: 4090 */
+#if !defined(_PR_HAVE_O_APPEND)
             fd->secret->appendMode = appendMode;
 #endif
             _PR_MD_INIT_FD_INHERITABLE(fd, PR_FALSE);
         }
     }
     return fd;
 }
 
@@ -799,30 +799,30 @@ PR_IMPLEMENT(PRStatus) PR_CreatePipe(
 
 #ifdef MOZ_UNICODE
 /* ================ UTF16 Interfaces ================================ */
 PR_IMPLEMENT(PRFileDesc*) PR_OpenFileUTF16(
     const PRUnichar *name, PRIntn flags, PRIntn mode)
 { 
     PRInt32 osfd;
     PRFileDesc *fd = 0;
-#if !defined(XP_UNIX) /* BugZilla: 4090 */
+#if !defined(_PR_HAVE_O_APPEND)
     PRBool  appendMode = ( PR_APPEND & flags )? PR_TRUE : PR_FALSE;
 #endif
    
     if (!_pr_initialized) _PR_ImplicitInitialization();
   
     /* Map pr open flags and mode to os specific flags */
     osfd = _PR_MD_OPEN_FILE_UTF16(name, flags, mode);
     if (osfd != -1) {
         fd = PR_AllocFileDesc(osfd, &_pr_fileMethods);
         if (!fd) {
             (void) _PR_MD_CLOSE_FILE(osfd);
         } else {
-#if !defined(XP_UNIX) /* BugZilla: 4090 */
+#if !defined(_PR_HAVE_O_APPEND)
             fd->secret->appendMode = appendMode;
 #endif
             _PR_MD_INIT_FD_INHERITABLE(fd, PR_FALSE);
         }
     }
     return fd;
 }