]> git.gag.com Git - debian/as31/blobdiff - as31/run.c
update patch to current sources, apply in tree
[debian/as31] / as31 / run.c
index 126d3b5a014e6ca31406aad3480079a7f4f20305..9e5263b08ffc4794c921ac964b0f5187825f80a8 100644 (file)
@@ -39,8 +39,8 @@ int run_as31(const char *infile, int lst, int use_stdout,
        char *incLineBuffer=NULL;
        int incSizeBuf=0;
        FILE* includeFile=NULL;
+       int fd;
 
-       uid_t uid; 
        /* first, figure out all the file names */
 
        dashl = lst;
@@ -95,18 +95,26 @@ int run_as31(const char *infile, int lst, int use_stdout,
                }
        }
        
-       uid = geteuid();
-       sprintf(tmpName,"/tmp/as31-%i-%ld.asm",uid,random());
-       fin = fopen(tmpName, "w");
+       sprintf(tmpName,"/tmp/as31-XXXXXX.asm");
+       fd = mkstemps(tmpName, 4);
+       if (fd == -1) {
+               mesg_f("Cannot create temp file\n");
+               if (outfile) free(outfile);
+               if (lstfile) free(lstfile);
+               return -1;
+       }
+       fin = fdopen(fd, "w");
        if (fin == NULL) {
                mesg_f("Cannot open temp file: %s\n",tmpName);
+               close(fd);
                if (outfile) free(outfile);
                if (lstfile) free(lstfile);
                return -1;
        }
 
        while (!feof(finPre)) {
-               getline(&lineBuffer,&sizeBuf,finPre);
+               if (getline(&lineBuffer,&sizeBuf,finPre) == -1)
+                       break;
                if ((includePtr=strstr(lineBuffer,INC_CMD))) {
                        includePtr=includePtr+strlen(INC_CMD);
                        while ((*includePtr==' ')||             //move includePtr to filename
@@ -131,7 +139,8 @@ int run_as31(const char *infile, int lst, int use_stdout,
                                mesg_f("Cannot open include file: %s\n",includePtr);
                        } else {
                                while (!feof(includeFile)) {
-                                       getline(&incLineBuffer,&incSizeBuf,includeFile);
+                                       if (getline(&incLineBuffer,&incSizeBuf,includeFile) == -1)
+                                               break;
                                        fprintf(fin,"%s",incLineBuffer);
                                        if (strlen(incLineBuffer)) {
                                                incLineCount++;