/[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.4 by jmc, Sat Feb 23 03:30:03 2008 UTC revision 1.5 by jmc, Tue Feb 26 17:05:00 2008 UTC
# Line 23  Line 23 
23   * SOFTWARE.   * SOFTWARE.
24   */   */
25  #include <stdio.h>  #include <stdio.h>
26    #include <stdlib.h>
27  #include <ctype.h>  #include <ctype.h>
28  #include <string.h>  #include <string.h>
29  #include <errno.h>  #include <errno.h>
30  #include <sys/types.h>  #include <sys/types.h>
31    #include <sys/stat.h>
32  #include <sys/param.h>  #include <sys/param.h>
33    #include <time.h>
34  #include <netdb.h>  #include <netdb.h>
35  #include <fcntl.h>  #include <fcntl.h>
36    #include <unistd.h>
37  #include "xmalloc.h"  #include "xmalloc.h"
38  #include "common.h"  #include "common.h"
39  #include "part.h"  #include "part.h"
40    
41    extern void warn(char *s);
42    
43  #ifndef MAXHOSTNAMELEN  #ifndef MAXHOSTNAMELEN
44  #define MAXHOSTNAMELEN 64  #define MAXHOSTNAMELEN 64
45  #endif  #endif
46    
47    #ifndef errno
48  extern int errno;  extern int errno;
49  /* extern char *malloc(); */  #endif
 extern char *getenv();  
50    
51  int overwrite_files = 0;  int overwrite_files = 0;
52  int didchat;  int didchat;
# Line 75  char *os_genid(void) Line 81  char *os_genid(void)
81          }          }
82      }      }
83    
84      result = (char *)malloc(25+strlen(hostname));      result = malloc(25+strlen(hostname));
85      sprintf(result, "%d.%d@%s", pid, curtime++, hostname);      sprintf(result, "%d.%lu@%s", pid, (unsigned long) curtime++, hostname);
86      return result;      return result;
87  }  }
88    
# Line 90  char *os_idtodir(char *id) Line 96  char *os_idtodir(char *id)
96          strcpy(buf, getenv("TMPDIR"));          strcpy(buf, getenv("TMPDIR"));
97      }      }
98      else {      else {
99          strcpy(buf, "/usr/tmp");          strcpy(buf, "/var/tmp");
100      }      }
101      strcat(buf, "/m-prts-");      strcat(buf, "/m-prts-");
102      p = getenv("USER");      p = getenv("USER");
# Line 137  FILE *os_createnewfile(char *fname) Line 143  FILE *os_createnewfile(char *fname)
143      FILE *ret;      FILE *ret;
144            
145  #ifdef O_EXCL  #ifdef O_EXCL
146      fd=open(fname, O_RDWR|O_CREAT|O_EXCL, 0644);      struct stat statbuf;
147    
148        if ((stat(fname, &statbuf) == 0) && (S_ISCHR(statbuf.st_mode))) {
149            fd=open(fname, O_RDWR);
150        }
151        else {
152            fd=open(fname, O_RDWR|O_CREAT|O_EXCL, 0644);
153        }
154  #else  #else
155      fd=open(fname, O_RDWR|O_CREAT|O_TRUNC, 0644);      fd=open(fname, O_RDWR|O_CREAT|O_TRUNC, 0644);
156  #endif  #endif
# Line 194  FILE *os_newtypedfile(char *fname, char Line 207  FILE *os_newtypedfile(char *fname, char
207          do {          do {
208              if (outfile) fclose(outfile);              if (outfile) fclose(outfile);
209              sprintf(buf, "part%d", ++filesuffix);              sprintf(buf, "part%d", ++filesuffix);
210          } while (outfile = fopen(buf, "r"));          } while ((outfile = fopen(buf, "r")));
211          fname = buf;          fname = buf;
212      }      }
213      else if (!overwrite_files && (outfile = fopen(fname, "r"))) {      else if (!overwrite_files && (outfile = fopen(fname, "r"))) {
# Line 202  FILE *os_newtypedfile(char *fname, char Line 215  FILE *os_newtypedfile(char *fname, char
215              fclose(outfile);              fclose(outfile);
216              sprintf(buf, "%s.%d", fname, ++filesuffix);              sprintf(buf, "%s.%d", fname, ++filesuffix);
217                    
218          } while (outfile = fopen(buf, "r"));          } while ((outfile = fopen(buf, "r")));
219          fname = buf;          fname = buf;
220      }      }
221    
# Line 228  FILE *os_newtypedfile(char *fname, char Line 241  FILE *os_newtypedfile(char *fname, char
241    
242      p = strchr(descfname, '/');      p = strchr(descfname, '/');
243      if (!p) p = descfname;      if (!p) p = descfname;
244      if (p = strrchr(p, '.')) *p = '\0';      if ((p = strrchr(p, '.'))) *p = '\0';
245    
246      strcat(descfname, ".desc");      strcat(descfname, ".desc");
247      (void) rename(TEMPFILENAME, descfname);      (void) rename(TEMPFILENAME, descfname);

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

  ViewVC Help
Powered by ViewVC 1.1.22