00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "common.h"
00038
00039 #include <stdlib.h>
00040 #include <stdio.h>
00041 #include <fcntl.h>
00042 #include <errno.h>
00043 #include <string.h>
00044 #ifdef HAVE_SYS_PARAM_H
00045 # include <sys/param.h>
00046 #endif
00047 #include <ctype.h>
00048 #include <math.h>
00049 #ifdef HAVE_STRING_H
00050 # include <string.h>
00051 #else
00052 # include <strings.h>
00053 #endif
00054
00055 #include "machine.h"
00056 #include "bu.h"
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 FILE *
00079 bu_fopen_uniq(const char *outfmt, const char *namefmt, int n)
00080 {
00081 char filename[MAXPATHLEN];
00082 int fd;
00083 FILE *fp;
00084
00085 if ( ! namefmt || ! *namefmt)
00086 bu_bomb("bu_uniq_file called with null string\n");
00087
00088 bu_semaphore_acquire( BU_SEM_SYSCALL);
00089 sprintf(filename, namefmt, n);
00090 if ((fd = open(filename, O_RDWR|O_CREAT|O_EXCL, 0600)) < 0) {
00091 fprintf(stderr, "Cannot open %s, %s\n", filename, strerror(errno));
00092 exit(-1);
00093 }
00094 if ( (fp=fdopen(fd, "w")) == (FILE *)NULL) {
00095 fprintf(stderr, strerror(errno));
00096 exit(-1);
00097 }
00098
00099 if (outfmt)
00100 fprintf(stderr, outfmt, filename);
00101
00102 bu_semaphore_release( BU_SEM_SYSCALL);
00103
00104 return fp;
00105 }
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116