/[MITgcm]/MITgcm/tools/mpack-1.6/unixos.c
ViewVC logotype

Diff of /MITgcm/tools/mpack-1.6/unixos.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.3 by jmc, Sat Feb 23 01:28:27 2008 UTC revision 1.4 by jmc, Sat Feb 23 03:30:03 2008 UTC
# Line 23  Line 23 
23   * SOFTWARE.   * SOFTWARE.
24   */   */
25  #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  
26  #include <ctype.h>  #include <ctype.h>
27  #include <string.h>  #include <string.h>
28  #include <errno.h>  #include <errno.h>
29  #include <sys/types.h>  #include <sys/types.h>
 #include <sys/stat.h>  
30  #include <sys/param.h>  #include <sys/param.h>
 #include <time.h>  
31  #include <netdb.h>  #include <netdb.h>
32  #include <fcntl.h>  #include <fcntl.h>
 #include <unistd.h>  
33  #include "xmalloc.h"  #include "xmalloc.h"
34  #include "common.h"  #include "common.h"
35  #include "part.h"  #include "part.h"
36    
 extern void warn(char *s);  
   
37  #ifndef MAXHOSTNAMELEN  #ifndef MAXHOSTNAMELEN
38  #define MAXHOSTNAMELEN 64  #define MAXHOSTNAMELEN 64
39  #endif  #endif
40    
 #ifndef errno  
41  extern int errno;  extern int errno;
42  #endif  /* extern char *malloc(); */
43    extern char *getenv();
44    
45  int overwrite_files = 0;  int overwrite_files = 0;
46  int didchat;  int didchat;
# Line 81  char *os_genid(void) Line 75  char *os_genid(void)
75          }          }
76      }      }
77    
78      result = malloc(25+strlen(hostname));      result = (char *)malloc(25+strlen(hostname));
79      sprintf(result, "%d.%lu@%s", pid, (unsigned long) curtime++, hostname);      sprintf(result, "%d.%d@%s", pid, curtime++, hostname);
80      return result;      return result;
81  }  }
82    
# Line 96  char *os_idtodir(char *id) Line 90  char *os_idtodir(char *id)
90          strcpy(buf, getenv("TMPDIR"));          strcpy(buf, getenv("TMPDIR"));
91      }      }
92      else {      else {
93          strcpy(buf, "/var/tmp");          strcpy(buf, "/usr/tmp");
94      }      }
95      strcat(buf, "/m-prts-");      strcat(buf, "/m-prts-");
96      p = getenv("USER");      p = getenv("USER");
# Line 143  FILE *os_createnewfile(char *fname) Line 137  FILE *os_createnewfile(char *fname)
137      FILE *ret;      FILE *ret;
138            
139  #ifdef O_EXCL  #ifdef O_EXCL
140      struct stat statbuf;      fd=open(fname, O_RDWR|O_CREAT|O_EXCL, 0644);
   
     if ((stat(fname, &statbuf) == 0) && (S_ISCHR(statbuf.st_mode))) {  
         fd=open(fname, O_RDWR);  
     }  
     else {  
         fd=open(fname, O_RDWR|O_CREAT|O_EXCL, 0644);  
     }  
141  #else  #else
142      fd=open(fname, O_RDWR|O_CREAT|O_TRUNC, 0644);      fd=open(fname, O_RDWR|O_CREAT|O_TRUNC, 0644);
143  #endif  #endif
# Line 207  FILE *os_newtypedfile(char *fname, char Line 194  FILE *os_newtypedfile(char *fname, char
194          do {          do {
195              if (outfile) fclose(outfile);              if (outfile) fclose(outfile);
196              sprintf(buf, "part%d", ++filesuffix);              sprintf(buf, "part%d", ++filesuffix);
197          } while ((outfile = fopen(buf, "r")));          } while (outfile = fopen(buf, "r"));
198          fname = buf;          fname = buf;
199      }      }
200      else if (!overwrite_files && (outfile = fopen(fname, "r"))) {      else if (!overwrite_files && (outfile = fopen(fname, "r"))) {
# Line 215  FILE *os_newtypedfile(char *fname, char Line 202  FILE *os_newtypedfile(char *fname, char
202              fclose(outfile);              fclose(outfile);
203              sprintf(buf, "%s.%d", fname, ++filesuffix);              sprintf(buf, "%s.%d", fname, ++filesuffix);
204                    
205          } while ((outfile = fopen(buf, "r")));          } while (outfile = fopen(buf, "r"));
206          fname = buf;          fname = buf;
207      }      }
208    
# Line 241  FILE *os_newtypedfile(char *fname, char Line 228  FILE *os_newtypedfile(char *fname, char
228    
229      p = strchr(descfname, '/');      p = strchr(descfname, '/');
230      if (!p) p = descfname;      if (!p) p = descfname;
231      if ((p = strrchr(p, '.'))) *p = '\0';      if (p = strrchr(p, '.')) *p = '\0';
232    
233      strcat(descfname, ".desc");      strcat(descfname, ".desc");
234      (void) rename(TEMPFILENAME, descfname);      (void) rename(TEMPFILENAME, descfname);

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

  ViewVC Help
Powered by ViewVC 1.1.22