Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20070127082703

Diff

Diff from 1.50 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/pcc/pcc/cc/cc/cc.c

Annotated File View

ragge
1.50
1 /*      $Id: cc.c,v 1.50 2007/01/27 08:27:03 ragge Exp $        */
ragge
1.3
2 /*
3  * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * Redistributions of source code and documentation must retain the above
10  * copyright notice, this list of conditions and the following disclaimer.
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditionsand the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * All advertising materials mentioning features or use of this software
15  * must display the following acknowledgement:
16  *      This product includes software developed or owned by Caldera
17  *      International, Inc.
18  * Neither the name of Caldera International, Inc. nor the names of other
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
23  * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED.  IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
27  * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
ragge
1.2
35
ragge
1.1
36 /*
ragge
1.3
37  * Front-end to the C compiler.
ragge
1.18
38  *
39  * Brief description of its syntax:
40  * - Files that end with .c are passed via cpp->ccom->as->ld
41  * - Files that end with .s are passed as->ld
42  * - Files that end with .o are passed directly to ld
43  * - Multiple files may be given on the command line.
44  * - Unrecognized options are all sent directly to ld.
45  * -c or -S cannot be combined with -o if multiple files are given.
46  *
47  * This file should be rewritten readable.
ragge
1.1
48  */
ragge
1.9
49 #include <sys/types.h>
ragge
1.36
50 #include <sys/wait.h>
ragge
1.2
51
ragge
1.1
52 #include <stdio.h>
53 #include <ctype.h>
54 #include <signal.h>
ragge
1.4
55 #include <string.h>
56 #include <fcntl.h>
57 #include <unistd.h>
58 #include <stdlib.h>
ragge
1.36
59 #include <stdarg.h>
60 #include <libgen.h>
pj
1.38
61 #include <errno.h>
ragge
1.24
62
ragge
1.39
63 #include "../../config.h"
64
ragge
1.24
65 #include "ccconfig.h"
ragge
1.3
66 /* C command */
ragge
1.1
67
ragge
1.20
68 #define MKS(x) _MKS(x)
69 #define _MKS(x) #x
70
71 /*
72  * Many specific definitions, should be declared elsewhere.
73  */
74 #define STDINC    "/usr/include"
75
ragge
1.3
76 #define SBSIZE 10000
ragge
1.12
77 #define MAXINC 100
ragge
1.3
78 #define MAXFIL 100
ragge
1.12
79 #define MAXLIB 10000
ragge
1.14
80 #define MAXAV  10000
ragge
1.3
81 #define MAXOPT 100
82 char    *tmp3;
83 char    *tmp4;
ragge
1.1
84 char    *outfile;
pj
1.31
85 char *copy(char *as),*setsuf(char *aschar ch);
ragge
1.4
86 int getsuf(char []);
87 int main(intchar *[]);
ragge
1.36
88 void error(char *, ...);
89 void errorx(int evalchar *, ...);
ragge
1.4
90 int nodup(char **, char *);
91 int callsys(char [], char *[]);
92 int cunlink(char *);
ragge
1.36
93 void dexit(int eval);
ragge
1.4
94 void idexit(int);
pj
1.30
95 char *gettmp();
ragge
1.14
96 char    *av[MAXAV];
ragge
1.3
97 char    *clist[MAXFIL];
98 char    *llist[MAXLIB];
ragge
1.4
99 char    alist[20];
ragge
1.43
100 char    *xlist[100];
101 int     xnum;
102 int     dflag;
ragge
1.3
103 int     pflag;
104 int     sflag;
105 int     cflag;
106 int     eflag;
107 int     gflag;
ragge
1.5
108 int     vflag;
ragge
1.7
109 int     tflag;
ragge
1.8
110 int     Eflag;
ragge
1.4
111 int     Oflag;
ragge
1.49
112 int     kflag;  /* generate PIC code */
ragge
1.3
113 int     proflag;
ragge
1.1
114 int     exfail;
ragge
1.10
115 int     Xflag;
ragge
1.14
116 int     nostartfilesBstatic;
ragge
1.20
117 int     nostdinc;
ragge
1.43
118 int     onlyas;
ragge
1.14
119
ragge
1.23
120 char    *pass0 = LIBEXECDIR "/ccom";
121 char    *passp = LIBEXECDIR "/cpp";
ragge
1.47
122 char    *Bflag;
ragge
1.20
123 char    *sysinc;
ragge
1.25
124 char *cppadd[] = CPPADD;
125 char *dynlinker[] = DYNLINKER;
126 char *crt0file = CRT0FILE;
127 char *startfiles[] = STARTFILES;
128 char *endfiles[] = ENDFILES;
129 char *cppmdadd[] = CPPMDADD;
ragge
1.50
130 #ifdef LIBCLIBS
131 char *libclibs[] = LIBCLIBS;
132 #else
133 char *libclibs[] = { "-lc"NULL };
134 #endif
ragge
1.48
135 #ifndef STARTLABEL
136 #define STARTLABEL "__start"
137 #endif
ragge
1.1
138
ragge
1.4
139 int
pj
1.26
140 main(int argcchar *argv[])
141 {
ragge
1.15
142         char *t, *u;
ragge
1.1
143         char *assource;
ragge
1.3
144         char **pv, *ptemp[MAXOPT], **pvt;
ragge
1.36
145         int ncnlijcnxona;
ragge
1.3
146
ragge
1.36
147         i = nc = nl = nxo = 0;
ragge
1.3
148         pv = ptemp;
149         while(++i < argc) {
ragge
1.18
150                 if (argv[i][0] == '-')
151                 switch (argv[i][1]) {
ragge
1.3
152                 default:
153                         goto passa;
ragge
1.22
154
ragge
1.47
155                 case 'B'/* other search paths for binaries */
156                         Bflag = &argv[i][2];
ragge
1.22
157                         break;
158
ragge
1.10
159                 case 'X':
160                         Xflag++;
161                         break;
ragge
1.15
162                 case 'W'/* Ignore (most of) W-flags */
163                         if (strncmp(argv[i], "-Wl,"4) == 0) {
164                                 /* options to the linker */
165                                 t = &argv[i][4];
166                                 while ((u = strchr(t','))) {
167                                         *u++ = 0;
168                                         llist[nl++] = t;
169                                         t = u;
170                                 }
171                                 llist[nl++] = t;
172                         }
173                         break;
174
ragge
1.49
175                 case 'f'/* GCC compatibility flags */
176                         if (strcmp(argv[i], "-fPIC") == 0)
177                                 kflag++;
178                         /* silently ignore the rest */
ragge
1.6
179                         break;
ragge
1.14
180
ragge
1.25
181                 case 'g'/* create debug output */
182                         gflag++;
183                         break;
184
ragge
1.20
185                 case 'i':
186                         if (strcmp(argv[i], "-isystem") == 0) {
187                                 sysinc = argv[++i];
188                         } else
189                                 goto passa;
190                         break;
191
ragge
1.49
192                 case 'k'/* generate PIC code */
193                         kflag++;
194                         break;
195
ragge
1.14
196                 case 'n'/* handle -n flags */
197                         if (strcmp(argv[i], "-nostdinc") == 0)
ragge
1.20
198                                 nostdinc++;
ragge
1.14
199                         else if (strcmp(argv[i], "-nostartfiles") == 0)
200                                 nostartfiles = 1;
201                         else
202                                 goto passa;
203                         break;
204
ragge
1.7
205                 case 'x':
ragge
1.43
206                         xlist[xnum++] = argv[i];
ragge
1.7
207                         break;
208                 case 't':
209                         tflag++;
210                         break;
ragge
1.1
211                 case 'S':
212                         sflag++;
213                         cflag++;
ragge
1.3
214                         break;
ragge
1.1
215                 case 'o':
ragge
1.18
216                         if (outfile)
ragge
1.36
217                                 errorx(8"too many -o");
ragge
1.18
218                         outfile = argv[++i];
ragge
1.3
219                         break;
ragge
1.1
220                 case 'O':
ragge
1.4
221                         Oflag++;
ragge
1.3
222                         break;
ragge
1.1
223                 case 'p':
224                         proflag++;
ragge
1.3
225                         break;
ragge
1.1
226                 case 'E':
ragge
1.8
227                         Eflag++;
228                         break;
ragge
1.1
229                 case 'P':
230                         pflag++;
ragge
1.3
231                         *pv++ = argv[i];
ragge
1.1
232                 case 'c':
233                         cflag++;
ragge
1.3
234                         break;
235
ragge
1.24
236 #if 0
ragge
1.3
237                 case '2':
238                         if(argv[i][2] == '\0')
239                                 pref = "/lib/crt2.o";
240                         else {
241                                 pref = "/lib/crt20.o";
242                         }
243                         break;
ragge
1.24
244 #endif
ragge
1.1
245                 case 'D':
246                 case 'I':
247                 case 'U':
248                 case 'C':
ragge
1.20
249                         *pv++ = argv[i];
ragge
1.3
250                         if (pv >= ptemp+MAXOPT)
251                                 {
ragge
1.36
252                                 error("Too many DIUC options");
ragge
1.3
253                                 --pv;
254                                 }
255                         break;
256
ragge
1.1
257                 case 'd':
ragge
1.3
258                         dflag++;
ragge
1.4
259                         strncpy(alistargv[i], 19);
ragge
1.3
260                         break;
ragge
1.5
261                 case 'v':
ragge
1.39
262                         printf("%s\n"VERSSTR);
ragge
1.5
263                         vflag++;
264                         break;
ragge
1.14
265
266                 case 's':
267                         if (strcmp(argv[i], "-static") == 0)
268                                 Bstatic = 1;
269                         else
270                                 goto passa;
271                         break;
ragge
1.3
272                 } else {
273                 passa:
274                         t = argv[i];
ragge
1.11
275                         if (*argv[i] == '-' && argv[i][1] == 'L')
276                                 ;
277                         else if((c=getsuf(t))=='c' || c=='s'|| Eflag) {
ragge
1.3
278                                 clist[nc++] = t;
279                                 if (nc>=MAXFIL)
280                                         {
ragge
1.36
281                                         error("Too many source files");
ragge
1.3
282                                         exit(1);
283                                         }
284                                 t = setsuf(t'o');
285                         }
286                         if (nodup(llistt)) {
287                                 llist[nl++] = t;
288                                 if (nl >= MAXLIB)
289                                         {
ragge
1.36
290                                         error("Too many object/library files");
ragge
1.3
291                                         exit(1);
292                                         }
293                                 if (getsuf(t)=='o')
294                                         nxo++;
ragge
1.1
295                         }
296                 }
297         }
ragge
1.18
298         /* Sanity checking */
299         if (nc == 0 && nl == 0)
ragge
1.36
300                 errorx(8"no input files");
ragge
1.18
301         if (outfile && (cflag || sflag) && nc > 1)
ragge
1.36
302                 errorx(8"-o given with -c || -S and more than one file");
ragge
1.19
303         if (outfile && clist[0] && strcmp(outfileclist[0]) == 0)
ragge
1.36
304                 errorx(8"output file will be clobbered");
ragge
1.18
305
ragge
1.4
306         if (gflagOflag = 0;
ragge
1.24
307 #if 0
308         if (proflag)
ragge
1.3
309                 pref = "/lib/mcrt0.o";
ragge
1.24
310 #endif
ragge
1.3
311         if(nc==0)
312                 goto nocom;
313         if (pflag==0) {
pj
1.30
314                 tmp3 = gettmp();
315                 tmp4 = gettmp();
ragge
1.1
316         }
ragge
1.3
317         if (signal(SIGINTSIG_IGN) != SIG_IGN/* interrupt */
ragge
1.1
318                 signal(SIGINTidexit);
ragge
1.3
319         if (signal(SIGTERMSIG_IGN) != SIG_IGN)        /* terminate */
ragge
1.1
320                 signal(SIGTERMidexit);
ragge
1.3
321         pvt = pv;
ragge
1.1
322         for (i=0i<nci++) {
ragge
1.18
323                 /*
324                  * C preprocessor
325                  */
ragge
1.37
326                 if (nc>1 && !Eflag)
ragge
1.1
327                         printf("%s:\n"clist[i]);
ragge
1.43
328                 onlyas = 0;
pj
1.32
329                 assource = tmp3;
ragge
1.3
330                 if (getsuf(clist[i])=='s') {
ragge
1.1
331                         assource = clist[i];
ragge
1.43
332                         onlyas = 1;
333                         goto assemble;
334                 } else if (getsuf(clist[i])=='S') {
335                         assource = clist[i];
336                         onlyas = 1;
pj
1.32
337                 }
ragge
1.1
338                 if (pflag)
339                         tmp4 = setsuf(clist[i], 'i');
ragge
1.5
340                 na = 0;
341                 av[na++] = "cpp";
ragge
1.20
342                 av[na++] = "-D__PCC__=" MKS(PCC_MAJOR);
ragge
1.40
343                 av[na++] = "-D__PCC_MINOR__=" MKS(PCC_MINOR);
344                 av[na++] = "-D__PCC_MINORMINOR__=" MKS(PCC_MINORMINOR);
ragge
1.20
345                 if (!nostdinc)
ragge
1.21
346                         av[na++] = "-S"av[na++] = STDINC;
ragge
1.20
347                 if (sysinc)
348                         av[na++] = "-S"av[na++] = sysinc;
ragge
1.5
349                 for (j = 0cppadd[j]; j++)
350                         av[na++] = cppadd[j];
ragge
1.24
351                 for (j = 0cppmdadd[j]; j++)
352                         av[na++] = cppmdadd[j];
ragge
1.7
353                 if (tflag)
ragge
1.20
354                         av[na++] = "-t";
ragge
1.7
355                 for(pv=ptemppv <pvtpv++)
356                         av[na++] = *pv;
ragge
1.5
357                 av[na++] = clist[i];
ragge
1.20
358                 if (!Eflag)
359                         av[na++] = tmp4;
ragge
1.3
360                 av[na++]=0;
361                 if (callsys(passpav))
362                         {exfail++; eflag++;}
ragge
1.11
363                 if (Eflag)
ragge
1.37
364                         continue;
ragge
1.43
365                 if (onlyas)
ragge
1.7
366                         goto assemble;
ragge
1.18
367
368                 /*
369                  * C compiler
370                  */
ragge
1.25
371                 na = 0;
372                 av[na++]= "ccom";
373                 if (gflag)
374                         av[na++] = "-g";
ragge
1.49
375                 if (kflag)
376                         av[na++] = "-k";
ragge
1.44
377                 if (Oflag) {
378                         av[na++] = "-xtemps";
379                 }
ragge
1.45
380                 for (j = 0j < xnumj++)
381                         av[na++] = xlist[j];
ragge
1.25
382                 av[na++] = tmp4;
ragge
1.3
383                 if (pflag || exfail)
384                         {
ragge
1.1
385                         cflag++;
386                         continue;
ragge
1.3
387                         }
ragge
1.16
388                 if(sflag) {
389                         if (outfile)
390                                 assource = tmp3 = outfile;
391                         else
392                                 assource = tmp3 = setsuf(clist[i], 's');
393                 }
ragge
1.25
394                 av[na++] = tmp3;
395 #if 0
ragge
1.3
396                 if (proflag) {
397                         av[3] = "-XP";
398                         av[4] = 0;
399                 } else
400                         av[3] = 0;
ragge
1.25
401 #endif
402                 av[na++] = NULL;
ragge
1.3
403                 if (callsys(pass0av)) {
ragge
1.1
404                         cflag++;
405                         eflag++;
406                         continue;
407                 }
408                 if (sflag)
409                         continue;
ragge
1.18
410
411                 /*
412                  * Assembler
413                  */
ragge
1.1
414         assemble:
ragge
1.49
415                 na = 0;
416                 av[na++] = "as";
417                 if (kflag)
418                         av[na++] = "-k";
419                 av[na++] = "-o";
ragge
1.18
420                 if (outfile && cflag)
ragge
1.49
421                         av[na++] = outfile;
ragge
1.18
422                 else
ragge
1.49
423                         av[na++] = setsuf(clist[i], 'o');
424                 av[na++] = onlyas ? tmp4 : assource;
425                 if (dflag)
426                         av[na++] = alist;
427                 av[na++] = 0;
ragge
1.21
428                 if (callsys("/bin/as"av)) {
ragge
1.1
429                         cflag++;
430                         eflag++;
ragge
1.7
431                         cunlink(tmp4);
ragge
1.1
432                         continue;
433                 }
ragge
1.7
434                 cunlink(tmp4);
ragge
1.1
435         }
ragge
1.18
436
ragge
1.37
437         if (Eflag)
438                 dexit(eflag);
439
ragge
1.18
440         /*
441          * Linker
442          */
ragge
1.1
443 nocom:
444         if (cflag==0 && nl!=0) {
ragge
1.6
445                 j = 0;
446                 av[j++] = "ld";
447                 av[j++] = "-X";
448                 av[j++] = "-d";
449                 av[j++] = "-e";
ragge
1.48
450                 av[j++] = STARTLABEL;
ragge
1.14
451                 if (Bstatic == 0) { /* Dynamic linkage */
ragge
1.24
452                         for (i = 0dynlinker[i]; i++)
453                                 av[j++] = dynlinker[i];
ragge
1.14
454                 }
ragge
1.1
455                 if (outfile) {
ragge
1.3
456                         av[j++] = "-o";
457                         av[j++] = outfile;
458                 }
ragge
1.14
459                 if (!nostartfiles) {
ragge
1.24
460                         av[j++] = crt0file;
461                         for (i = 0startfiles[i]; i++)
462                                 av[j++] = startfiles[i];
ragge
1.14
463                 }
ragge
1.24
464                 i = 0;
ragge
1.14
465                 while(i<nl) {
ragge
1.3
466                         av[j++] = llist[i++];
ragge
1.14
467                         if (j >= MAXAV)
ragge
1.36
468                                 error("Too many ld options");
ragge
1.14
469                 }
ragge
1.11
470 #if 0
ragge
1.3
471                 if (gflag)
472                         av[j++] = "-lg";
ragge
1.11
473 #endif
ragge
1.50
474                 for (i = 0libclibs[i]; i++)
475                         av[j++] = libclibs[i];
ragge
1.14
476                 if (!nostartfiles) {
ragge
1.24
477                         for (i = 0endfiles[i]; i++)
478                                 av[j++] = endfiles[i];
ragge
1.14
479                 }
ragge
1.3
480                 av[j++] = 0;
481                 eflag |= callsys("/bin/ld"av);
ragge
1.1
482                 if (nc==1 && nxo==1 && eflag==0)
ragge
1.3
483                         cunlink(setsuf(clist[0], 'o'));
ragge
1.46
484                 else if (nc > 0 && eflag == 0) {
485                         /* remove .o files XXX ugly */
486                         for (i = 0i < nci++)
487                                 cunlink(setsuf(clist[i], 'o'));
488                 }
ragge
1.1
489         }
ragge
1.36
490         dexit(eflag);
ragge
1.4
491         return 0;
ragge
1.1
492 }
493
ragge
1.36
494 /*
495  * exit and cleanup after interrupt.
496  */
ragge
1.4
497 void
498 idexit(int arg)
ragge
1.1
499 {
ragge
1.36
500         dexit(100);
ragge
1.1
501 }
502
ragge
1.36
503 /*
504  * exit and cleanup.
505  */
ragge
1.4
506 void
ragge
1.36
507 dexit(int eval)
ragge
1.1
508 {
ragge
1.10
509         if (!pflag && !Xflag) {
ragge
1.1
510                 if (sflag==0)
511                         cunlink(tmp3);
512                 cunlink(tmp4);
513         }
ragge
1.36
514         exit(eval);
ragge
1.1
515 }
516
ragge
1.36
517 static void
518 ccerror(char *sva_list ap)
ragge
1.1
519 {
ragge
1.36
520         vfprintf(Eflag ? stderr : stdoutsap);
ragge
1.8
521         putc('\n'Eflagstderr : stdout);
ragge
1.1
522         exfail++;
523         cflag++;
524         eflag++;
525 }
526
ragge
1.36
527 /*
528  * complain a bit.
529  */
530 void
531 error(char *s, ...)
532 {
533         va_list ap;
534
535         va_start(aps);
536         ccerror(sap);
537         va_end(ap);
538 }
539
540 /*
541  * complain a bit and then exit.
542  */
ragge
1.18
543 void
ragge
1.36
544 errorx(int evalchar *s, ...)
ragge
1.18
545 {
ragge
1.36
546         va_list ap;
547
548         va_start(aps);
549         ccerror(sap);
550         va_end(ap);
551         dexit(eval);
ragge
1.18
552 }
ragge
1.3
553
ragge
1.4
554 int
ragge
1.3
555 getsuf(as)
556 char as[];
ragge
1.1
557 {
558         register char *s;
559
ragge
1.4
560         if ((s = strrchr(as'.')) && s[1] != '\0' && s[2] == '\0')
561                 return s[1];
ragge
1.3
562         return(0);
ragge
1.1
563 }
564
ragge
1.36
565 /*
566  * Get basename of string s and change its suffix to ch.
567  */
ragge
1.1
568 char *
ragge
1.36
569 setsuf(char *schar ch)
ragge
1.1
570 {
ragge
1.36
571         s = copy(basename(s));
pj
1.31
572         s[strlen(s) - 1] = ch;
ragge
1.36
573         return(s);
ragge
1.1
574 }
575
ragge
1.4
576 int
ragge
1.3
577 callsys(fv)
578 char f[], *v[]; {
ragge
1.1
579         int tstatus;
ragge
1.4
580         char *s;
ragge
1.5
581
582         if (vflag) {
ragge
1.41
583                 fprintf(stderr"%s "f);
584                 for (t = 1v[t]; t++)
ragge
1.6
585                         fprintf(stderr"%s "v[t]);
586                 fprintf(stderr"\n");
ragge
1.5
587         }
ragge
1.1
588
ragge
1.3
589         if ((t=fork())==0) {
ragge
1.47
590                 if (Bflag) {
591                         char *a = malloc(strlen(Bflag) + 8);
592                         if ((s = strrchr(f'/'))) {
593                                 strcpy(aBflag);
594                                 strcat(as);
595                                 execv(av);
596                         }
597                 }
ragge
1.1
598                 execv(fv);
ragge
1.4
599                 if ((s = strrchr(f'/')))
600                         execvp(s+1v);
ragge
1.1
601                 printf("Can't find %s\n"f);
ragge
1.3
602                 exit(100);
603         } else
604                 if (t == -1) {
605                         printf("Try again\n");
606                         return(100);
607                 }
608         while(t!=wait(&status));
ragge
1.1
609         if ((t=(status&0377)) != 0 && t!=14) {
ragge
1.3
610                 if (t!=2)               /* interrupt */
ragge
1.36
611                         errorx(8"Fatal error in %s"f);
612                 dexit(eflag);
ragge
1.1
613         }
ragge
1.3
614         return((status>>8) & 0377);
ragge
1.1
615 }
616
ragge
1.3
617 char *
pj
1.28
618 copy(char *as)
ragge
1.3
619 {
pj
1.28
620         char *p;
621
ragge
1.36
622         if ((p = strdup(as)) == NULL)
623                 errorx(8"no space for file names");
ragge
1.3
624
pj
1.28
625         return p;
ragge
1.3
626 }
627
ragge
1.4
628 int
ragge
1.3
629 nodup(los)
630 char **l, *os;
ragge
1.1
631 {
632         register char *t, *s;
633         register int c;
634
635         s = os;
636         if (getsuf(s) != 'o')
ragge
1.3
637                 return(1);
ragge
1.4
638         while((t = *l++)) {
639                 while((c = *s++))
ragge
1.1
640                         if (c != *t++)
641                                 break;
ragge
1.3
642                 if (*t=='\0' && c=='\0')
643                         return(0);
ragge
1.1
644                 s = os;
645         }
ragge
1.3
646         return(1);
ragge
1.1
647 }
648
ragge
1.4
649 int
ragge
1.3
650 cunlink(f)
651 char *f;
ragge
1.1
652 {
ragge
1.13
653         if (f==0 || Xflag)
ragge
1.3
654                 return(0);
655         return(unlink(f));
ragge
1.1
656 }
pj
1.30
657
658 char *
659 gettmp()
660 {
661         char *sfn = strdup("/tmp/ctm.XXXXXX");
662         int fd = -1;
663
664         if ((fd = mkstemp(sfn)) == -1) {
665                 fprintf(stderr"%s: %s\n"sfnstrerror(errno));
666                 exit(8);
667         }
668         close(fd);
669
670         return sfn;
671 }
FishEye: Open Source License registered to PCC.
Your maintenance has expired. You can renew your license at http://www.atlassian.com/fisheye/renew
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-08-27 20:58 +0200