View | Details | Raw Unified | Return to bug 19642
Collapse All | Expand All

(-)gnu/usr.bin/patch/backupfile.c (-1 / +1 lines)
Lines 216-222 Link Here
216
     char *str1, *str2;
216
     char *str1, *str2;
217
{
217
{
218
  char *newstr;
218
  char *newstr;
219
  char str1_length = strlen (str1);
219
  int str1_length = strlen (str1);
220
220
221
  newstr = malloc (str1_length + strlen (str2) + 1);
221
  newstr = malloc (str1_length + strlen (str2) + 1);
222
  if (newstr == 0)
222
  if (newstr == 0)
(-)gnu/usr.bin/patch/common.h (-6 / +10 lines)
Lines 29-36 Link Here
29
#define Fclose (void)fclose
29
#define Fclose (void)fclose
30
#define Fflush (void)fflush
30
#define Fflush (void)fflush
31
#define Sprintf (void)sprintf
31
#define Sprintf (void)sprintf
32
#define Mktemp (void)mktemp
32
#define Snprintf (void)snprintf
33
#define Strcpy (void)strcpy
33
#define Strcpy (void)strcpy
34
#define Strlcpy (void)strlcpy
34
#define Strcat (void)strcat
35
#define Strcat (void)strcat
35
36
36
/* NeXT declares malloc and realloc incompatibly from us in some of
37
/* NeXT declares malloc and realloc incompatibly from us in some of
Lines 41-46 Link Here
41
#include <assert.h>
42
#include <assert.h>
42
#include <sys/types.h>
43
#include <sys/types.h>
43
#include <sys/stat.h>
44
#include <sys/stat.h>
45
#include <sys/param.h>
44
#include <ctype.h>
46
#include <ctype.h>
45
#include <signal.h>
47
#include <signal.h>
46
#undef malloc
48
#undef malloc
Lines 117-124 Link Here
117
EXT bool ok_to_create_file INIT(FALSE);
119
EXT bool ok_to_create_file INIT(FALSE);
118
EXT char *bestguess INIT(Nullch);	/* guess at correct filename */
120
EXT char *bestguess INIT(Nullch);	/* guess at correct filename */
119
121
122
#define REJNAMESIZ 128
120
EXT char *outname INIT(Nullch);
123
EXT char *outname INIT(Nullch);
121
EXT char rejname[128];
124
EXT char rejname[REJNAMESIZ];
122
125
123
EXT char *origprae INIT(Nullch);
126
EXT char *origprae INIT(Nullch);
124
127
Lines 150-160 Link Here
150
#define UNI_DIFF 5
153
#define UNI_DIFF 5
151
EXT int diff_type INIT(0);
154
EXT int diff_type INIT(0);
152
155
156
#define DEFSIZ 128
153
EXT bool do_defines INIT(FALSE);	/* patch using ifdef, ifndef, etc. */
157
EXT bool do_defines INIT(FALSE);	/* patch using ifdef, ifndef, etc. */
154
EXT char if_defined[128];		/* #ifdef xyzzy */
158
EXT char if_defined[DEFSIZ];		/* #ifdef xyzzy */
155
EXT char not_defined[128];		/* #ifndef xyzzy */
159
EXT char not_defined[DEFSIZ];		/* #ifndef xyzzy */
156
EXT char else_defined[] INIT("#else\n");/* #else */
160
EXT char else_defined[] INIT("#else\n");/* #else */
157
EXT char end_defined[128];		/* #endif xyzzy */
161
EXT char end_defined[DEFSIZ];		/* #endif xyzzy */
158
162
159
EXT char *revision INIT(Nullch);	/* prerequisite revision, if any */
163
EXT char *revision INIT(Nullch);	/* prerequisite revision, if any */
160
164
Lines 172-178 Link Here
172
char *strcpy();
176
char *strcpy();
173
char *strcat();
177
char *strcat();
174
#endif
178
#endif
175
char *mktemp();
179
int mkstemp();
176
#ifdef HAVE_UNISTD_H
180
#ifdef HAVE_UNISTD_H
177
#include <unistd.h>
181
#include <unistd.h>
178
#else
182
#else
(-)gnu/usr.bin/patch/getopt.c (-1 / +1 lines)
Lines 445-451 Link Here
445
      int exact = 0;
445
      int exact = 0;
446
      int ambig = 0;
446
      int ambig = 0;
447
      const struct option *pfound = NULL;
447
      const struct option *pfound = NULL;
448
      int indfound;
448
      int indfound = 0;
449
449
450
      while (*s && *s != '=')
450
      while (*s && *s != '=')
451
	s++;
451
	s++;
(-)gnu/usr.bin/patch/inp.c (-13 / +17 lines)
Lines 18-24 Link Here
18
18
19
/* Input-file-with-indexable-lines abstract type */
19
/* Input-file-with-indexable-lines abstract type */
20
20
21
static long i_size;			/* size of the input file */
21
static off_t i_size;			/* size of the input file */
22
static char *i_womp;			/* plan a buffer for entire file */
22
static char *i_womp;			/* plan a buffer for entire file */
23
static char **i_ptr;			/* pointers to lines in i_womp */
23
static char **i_ptr;			/* pointers to lines in i_womp */
24
24
Lines 117-123 Link Here
117
	s = lbuf + 20;
117
	s = lbuf + 20;
118
	strncpy(s, filename, pathlen);
118
	strncpy(s, filename, pathlen);
119
119
120
#define try(f,a1,a2) (Sprintf(s + pathlen, f, a1, a2), stat(s, &cstat) == 0)
120
#define try(f,a1,a2)							    \
121
		(Snprintf(s + pathlen, sizeof lbuf - (s + pathlen - lbuf),  \
122
		 f, a1, a2), stat(s, &cstat) == 0)
121
	if ((   try("RCS/%s%s", filebase, RCSSUFFIX)
123
	if ((   try("RCS/%s%s", filebase, RCSSUFFIX)
122
	     || try("RCS/%s%s", filebase,        "")
124
	     || try("RCS/%s%s", filebase,        "")
123
	     || try(    "%s%s", filebase, RCSSUFFIX))
125
	     || try(    "%s%s", filebase, RCSSUFFIX))
Lines 127-139 Link Here
127
	    (statfailed
129
	    (statfailed
128
	     || (  (filestat.st_dev ^ cstat.st_dev)
130
	     || (  (filestat.st_dev ^ cstat.st_dev)
129
		 | (filestat.st_ino ^ cstat.st_ino)))) {
131
		 | (filestat.st_ino ^ cstat.st_ino)))) {
130
	    Sprintf(buf, output_elsewhere?CHECKOUT:CHECKOUT_LOCKED, filename);
132
	    Snprintf(buf, sizeof(buf),
131
	    Sprintf(lbuf, RCSDIFF, filename);
133
		output_elsewhere?CHECKOUT:CHECKOUT_LOCKED, filename);
134
	    Snprintf(lbuf, sizeof(lbuf), RCSDIFF, filename);
132
	    cs = "RCS";
135
	    cs = "RCS";
133
	} else if (   try("SCCS/%s%s", SCCSPREFIX, filebase)
136
	} else if (   try("SCCS/%s%s", SCCSPREFIX, filebase)
134
		   || try(     "%s%s", SCCSPREFIX, filebase)) {
137
		   || try(     "%s%s", SCCSPREFIX, filebase)) {
135
	    Sprintf(buf, output_elsewhere?GET:GET_LOCKED, s);
138
	    Snprintf(buf, sizeof(buf), output_elsewhere?GET:GET_LOCKED, s);
136
	    Sprintf(lbuf, SCCSDIFF, s, filename);
139
	    Snprintf(lbuf, sizeof(lbuf), SCCSDIFF, s, filename);
137
	    cs = "SCCS";
140
	    cs = "SCCS";
138
	} else if (statfailed)
141
	} else if (statfailed)
139
	    fatal2("can't find %s\n", filename);
142
	    fatal2("can't find %s\n", filename);
Lines 172-186 Link Here
172
#ifdef lint
175
#ifdef lint
173
    i_womp = Nullch;
176
    i_womp = Nullch;
174
#else
177
#else
175
    i_womp = malloc((MEM)(i_size+2));	/* lint says this may alloc less than */
178
    i_womp = (char *)malloc((MEM)(i_size+2));
179
					/* lint says this may alloc less than */
176
					/* i_size, but that's okay, I think. */
180
					/* i_size, but that's okay, I think. */
177
#endif
181
#endif
178
    if (i_womp == Nullch)
182
    if (i_womp == Nullch)
179
	return FALSE;
183
	return FALSE;
180
    if ((ifd = open(filename, 0)) < 0)
184
    if ((ifd = open(filename, O_RDONLY)) < 0)
181
	pfatal2("can't open file %s", filename);
185
	pfatal2("can't open file %s", filename);
182
#ifndef lint
186
#ifndef lint
183
    if (read(ifd, i_womp, (int)i_size) != i_size) {
187
    if (read(ifd, i_womp, (size_t)i_size) != i_size) {
184
	Close(ifd);	/* probably means i_size > 15 or 16 bits worth */
188
	Close(ifd);	/* probably means i_size > 15 or 16 bits worth */
185
	free(i_womp);	/* at this point it doesn't matter if i_womp was */
189
	free(i_womp);	/* at this point it doesn't matter if i_womp was */
186
	return FALSE;	/*   undersized. */
190
	return FALSE;	/*   undersized. */
Lines 296-303 Link Here
296
    Fseek(ifp, 0L, 0);		/* rewind file */
300
    Fseek(ifp, 0L, 0);		/* rewind file */
297
    lines_per_buf = BUFFERSIZE / maxlen;
301
    lines_per_buf = BUFFERSIZE / maxlen;
298
    tireclen = maxlen;
302
    tireclen = maxlen;
299
    tibuf[0] = malloc((MEM)(BUFFERSIZE + 1));
303
    tibuf[0] = (char *)malloc((MEM)(BUFFERSIZE + 1));
300
    tibuf[1] = malloc((MEM)(BUFFERSIZE + 1));
304
    tibuf[1] = (char *)malloc((MEM)(BUFFERSIZE + 1));
301
    if (tibuf[1] == Nullch)
305
    if (tibuf[1] == Nullch)
302
	fatal1("out of memory\n");
306
	fatal1("out of memory\n");
303
    for (i=1; ; i++) {
307
    for (i=1; ; i++) {
Lines 315-321 Link Here
315
    }
319
    }
316
    Fclose(ifp);
320
    Fclose(ifp);
317
    Close(tifd);
321
    Close(tifd);
318
    if ((tifd = open(TMPINNAME, 0)) < 0) {
322
    if ((tifd = open(TMPINNAME, O_RDONLY)) < 0) {
319
	pfatal2("can't reopen file %s", TMPINNAME);
323
	pfatal2("can't reopen file %s", TMPINNAME);
320
    }
324
    }
321
}
325
}
Lines 342-348 Link Here
342
	else {
346
	else {
343
	    tiline[whichbuf] = baseline;
347
	    tiline[whichbuf] = baseline;
344
#ifndef lint		/* complains of long accuracy */
348
#ifndef lint		/* complains of long accuracy */
345
	    Lseek(tifd, (long)baseline / lines_per_buf * BUFFERSIZE, 0);
349
	    Lseek(tifd, (off_t)baseline / lines_per_buf * BUFFERSIZE, 0);
346
#endif
350
#endif
347
	    if (read(tifd, tibuf[whichbuf], BUFFERSIZE) < 0)
351
	    if (read(tifd, tibuf[whichbuf], BUFFERSIZE) < 0)
348
		pfatal2("error reading tmp file %s", TMPINNAME);
352
		pfatal2("error reading tmp file %s", TMPINNAME);
(-)gnu/usr.bin/patch/patch.c (-9 / +26 lines)
Lines 115-121 Link Here
115
bool patch_match();
115
bool patch_match();
116
bool similar();
116
bool similar();
117
void re_input();
117
void re_input();
118
#ifdef __GNUC__
119
void my_exit() __attribute__((noreturn));
120
#else
118
void my_exit();
121
void my_exit();
122
#endif
119
123
120
/* TRUE if -E was specified on command line.  */
124
/* TRUE if -E was specified on command line.  */
121
static int remove_empty_files = FALSE;
125
static int remove_empty_files = FALSE;
Lines 170-191 Link Here
170
      TMPOUTNAME = (char *) malloc (tmpname_len);
174
      TMPOUTNAME = (char *) malloc (tmpname_len);
171
      strcpy (TMPOUTNAME, tmpdir);
175
      strcpy (TMPOUTNAME, tmpdir);
172
      strcat (TMPOUTNAME, "/patchoXXXXXX");
176
      strcat (TMPOUTNAME, "/patchoXXXXXX");
173
      Mktemp(TMPOUTNAME);
177
      if ((i = mkstemp(TMPOUTNAME)) < 0)
178
	pfatal2("can't create %s", TMPOUTNAME);
179
      Close(i);
174
180
175
      TMPINNAME = (char *) malloc (tmpname_len);
181
      TMPINNAME = (char *) malloc (tmpname_len);
176
      strcpy (TMPINNAME, tmpdir);
182
      strcpy (TMPINNAME, tmpdir);
177
      strcat (TMPINNAME, "/patchiXXXXXX");
183
      strcat (TMPINNAME, "/patchiXXXXXX");
178
      Mktemp(TMPINNAME);
184
      if ((i = mkstemp(TMPINNAME)) < 0)
185
	pfatal2("can't create %s", TMPINNAME);
186
      Close(i);
179
187
180
      TMPREJNAME = (char *) malloc (tmpname_len);
188
      TMPREJNAME = (char *) malloc (tmpname_len);
181
      strcpy (TMPREJNAME, tmpdir);
189
      strcpy (TMPREJNAME, tmpdir);
182
      strcat (TMPREJNAME, "/patchrXXXXXX");
190
      strcat (TMPREJNAME, "/patchrXXXXXX");
183
      Mktemp(TMPREJNAME);
191
      if ((i = mkstemp(TMPREJNAME)) < 0)
192
	pfatal2("can't create %s", TMPREJNAME);
193
      Close(i);
184
194
185
      TMPPATNAME = (char *) malloc (tmpname_len);
195
      TMPPATNAME = (char *) malloc (tmpname_len);
186
      strcpy (TMPPATNAME, tmpdir);
196
      strcpy (TMPPATNAME, tmpdir);
187
      strcat (TMPPATNAME, "/patchpXXXXXX");
197
      strcat (TMPPATNAME, "/patchpXXXXXX");
188
      Mktemp(TMPPATNAME);
198
      if ((i = mkstemp(TMPPATNAME)) < 0)
199
	pfatal2("can't create %s", TMPPATNAME);
200
      Close(i);
201
189
    }
202
    }
190
203
191
    {
204
    {
Lines 383-389 Link Here
383
	if (failed) {
396
	if (failed) {
384
	    failtotal += failed;
397
	    failtotal += failed;
385
	    if (!*rejname) {
398
	    if (!*rejname) {
386
		Strcpy(rejname, outname);
399
                if (strlcpy(rejname, outname, sizeof(rejname) - sizeof(".rej"))
400
		    >= sizeof(rejname) - sizeof(".rej"))
401
                    fatal2("filename %s is too long\n", outname);
387
		addext(rejname, ".rej", '#');
402
		addext(rejname, ".rej", '#');
388
	    }
403
	    }
389
	    if (skip_rest_of_patch) {
404
	    if (skip_rest_of_patch) {
Lines 519-527 Link Here
519
	    	do_defines = TRUE;
534
	    	do_defines = TRUE;
520
		if (!isalpha((unsigned char)*optarg) && '_' != *optarg)
535
		if (!isalpha((unsigned char)*optarg) && '_' != *optarg)
521
		    fatal1("argument to -D is not an identifier\n");
536
		    fatal1("argument to -D is not an identifier\n");
522
		Sprintf(if_defined, "#ifdef %s\n", optarg);
537
		Snprintf(if_defined, sizeof if_defined, "#ifdef %s\n", optarg);
523
		Sprintf(not_defined, "#ifndef %s\n", optarg);
538
		Snprintf(not_defined, sizeof not_defined, "#ifndef %s\n",
524
		Sprintf(end_defined, "#endif /* %s */\n", optarg);
539
		    optarg);
540
		Snprintf(end_defined, sizeof end_defined, "#endif /* %s */\n",
541
		    optarg);
525
		break;
542
		break;
526
	    case 'e':
543
	    case 'e':
527
		diff_type = ED_DIFF;
544
		diff_type = ED_DIFF;
Lines 557-563 Link Here
557
		    strippath = 0;
574
		    strippath = 0;
558
		break;
575
		break;
559
	    case 'r':
576
	    case 'r':
560
		Strcpy(rejname, optarg);
577
		Strlcpy(rejname, optarg, sizeof(rejname));
561
		break;
578
		break;
562
	    case 'R':
579
	    case 'R':
563
		reverse = TRUE;
580
		reverse = TRUE;
(-)gnu/usr.bin/patch/pch.c (-2 / +2 lines)
Lines 1051-1058 Link Here
1051
	    else
1051
	    else
1052
		indent++;
1052
		indent++;
1053
	}
1053
	}
1054
	if (buf != s)
1054
	if (buf != s && strlcpy(buf, s, sizeof(buf)) >= sizeof(buf))
1055
	    Strcpy(buf, s);
1055
	    fatal1("buffer too small in pgets()\n");
1056
    }
1056
    }
1057
    return ret;
1057
    return ret;
1058
}
1058
}
(-)gnu/usr.bin/patch/util.c (-59 / +43 lines)
Lines 4-10 Link Here
4
#include "util.h"
4
#include "util.h"
5
#include "backupfile.h"
5
#include "backupfile.h"
6
6
7
#ifdef __GNUC__
8
void my_exit() __attribute__((noreturn));
9
#else
7
void my_exit();
10
void my_exit();
11
#endif
8
12
9
#ifndef HAVE_STRERROR
13
#ifndef HAVE_STRERROR
10
static char *
14
static char *
Lines 27-33 Link Here
27
move_file(from,to)
31
move_file(from,to)
28
char *from, *to;
32
char *from, *to;
29
{
33
{
30
    char bakname[512];
34
    char bakname[MAXPATHLEN];
31
    Reg1 char *s;
35
    Reg1 char *s;
32
    Reg2 int i;
36
    Reg2 int i;
33
    Reg3 int fromfd;
37
    Reg3 int fromfd;
Lines 39-45 Link Here
39
	if (debug & 4)
43
	if (debug & 4)
40
	    say2("Moving %s to stdout.\n", from);
44
	    say2("Moving %s to stdout.\n", from);
41
#endif
45
#endif
42
	fromfd = open(from, 0);
46
	fromfd = open(from, O_RDONLY);
43
	if (fromfd < 0)
47
	if (fromfd < 0)
44
	    pfatal2("internal error, can't reopen %s", from);
48
	    pfatal2("internal error, can't reopen %s", from);
45
	while ((i=read(fromfd, buf, sizeof buf)) > 0)
49
	while ((i=read(fromfd, buf, sizeof buf)) > 0)
Lines 50-63 Link Here
50
    }
54
    }
51
55
52
    if (origprae) {
56
    if (origprae) {
53
	Strcpy(bakname, origprae);
57
	if (strlcpy(bakname, origprae, sizeof(bakname)) >= sizeof(bakname) ||
54
	Strcat(bakname, to);
58
	    strlcat(bakname, to, sizeof(bakname)) >= sizeof(bakname))
59
	    fatal2("filename %s too long for buffer\n", origprae);
55
    } else {
60
    } else {
56
#ifndef NODIR
61
#ifndef NODIR
57
	char *backupname = find_backup_file_name(to);
62
	char *backupname = find_backup_file_name(to);
58
	if (backupname == (char *) 0)
63
	if (backupname == (char *) 0)
59
	    fatal1("out of memory\n");
64
	    fatal1("out of memory\n");
60
	Strcpy(bakname, backupname);
65
	if (strlcpy(bakname, backupname, sizeof(bakname)) >= sizeof(bakname))
66
	    fatal2("filename %s too long for buffer\n", backupname);
61
	free(backupname);
67
	free(backupname);
62
#else /* NODIR */
68
#else /* NODIR */
63
	Strcpy(bakname, to);
69
	Strcpy(bakname, to);
Lines 111-117 Link Here
111
	      to, from, strerror(errno));
117
	      to, from, strerror(errno));
112
	    return -1;
118
	    return -1;
113
	}
119
	}
114
	fromfd = open(from, 0);
120
	fromfd = open(from, O_RDONLY);
115
	if (fromfd < 0)
121
	if (fromfd < 0)
116
	    pfatal2("internal error, can't reopen %s", from);
122
	    pfatal2("internal error, can't reopen %s", from);
117
	while ((i=read(fromfd, buf, sizeof buf)) > 0)
123
	while ((i=read(fromfd, buf, sizeof buf)) > 0)
Lines 137-143 Link Here
137
    tofd = creat(to, 0666);
143
    tofd = creat(to, 0666);
138
    if (tofd < 0)
144
    if (tofd < 0)
139
	pfatal2("can't create %s", to);
145
	pfatal2("can't create %s", to);
140
    fromfd = open(from, 0);
146
    fromfd = open(from, O_RDONLY);
141
    if (fromfd < 0)
147
    if (fromfd < 0)
142
	pfatal2("internal error, can't reopen %s", from);
148
	pfatal2("internal error, can't reopen %s", from);
143
    while ((i=read(fromfd, buf, sizeof buf)) > 0)
149
    while ((i=read(fromfd, buf, sizeof buf)) > 0)
Lines 160-166 Link Here
160
	s = "Oops";
166
	s = "Oops";
161
    t = s;
167
    t = s;
162
    while (*t++);
168
    while (*t++);
163
    rv = malloc((MEM) (t - s));
169
    rv = (char *)malloc((MEM) (t - s));
164
    if (rv == Nullch) {
170
    if (rv == Nullch) {
165
	if (using_plan_a)
171
	if (using_plan_a)
166
	    out_of_mem = TRUE;
172
	    out_of_mem = TRUE;
Lines 236-242 Link Here
236
    int r;
242
    int r;
237
    bool tty2 = isatty(2);
243
    bool tty2 = isatty(2);
238
244
239
    Sprintf(buf, pat, arg1, arg2, arg3);
245
    Snprintf(buf, sizeof buf, pat, arg1, arg2, arg3);
240
    Fflush(stderr);
246
    Fflush(stderr);
241
    write(2, buf, strlen(buf));
247
    write(2, buf, strlen(buf));
242
    if (tty2) {				/* might be redirected to a file */
248
    if (tty2) {				/* might be redirected to a file */
Lines 247-253 Link Here
247
	write(1, buf, strlen(buf));
253
	write(1, buf, strlen(buf));
248
	r = read(1, buf, sizeof buf);
254
	r = read(1, buf, sizeof buf);
249
    }
255
    }
250
    else if ((ttyfd = open("/dev/tty", 2)) >= 0 && isatty(ttyfd)) {
256
    else if ((ttyfd = open("/dev/tty", O_RDWR)) >= 0 && isatty(ttyfd)) {
251
					/* might be deleted or unwriteable */
257
					/* might be deleted or unwriteable */
252
	write(ttyfd, buf, strlen(buf));
258
	write(ttyfd, buf, strlen(buf));
253
	r = read(ttyfd, buf, sizeof buf);
259
	r = read(ttyfd, buf, sizeof buf);
Lines 319-363 Link Here
319
Reg1 char *filename;
325
Reg1 char *filename;
320
bool striplast;
326
bool striplast;
321
{
327
{
322
    char tmpbuf[256];
328
323
    Reg2 char *s = tmpbuf;
329
    char *tmpbuf;
324
    char *dirv[20];		/* Point to the NULs between elements.  */
330
325
    Reg3 int i;
331
    if ((tmpbuf = strdup(filename)) == NULL)
326
    Reg4 int dirvp = 0;		/* Number of finished entries in dirv. */
332
	fatal1("out of memory\n");
327
333
328
    /* Copy `filename' into `tmpbuf' with a NUL instead of a slash
334
    if (striplast) {
329
       between the directories.  */
335
	char *s = strrchr(tmpbuf, '/');
330
    while (*filename) {
336
	if (s == NULL)
331
	if (*filename == '/') {
337
	    return; /* nothing to be done */
332
	    filename++;
338
	*s = '\0';
333
	    dirv[dirvp++] = s;
334
	    *s++ = '\0';
335
	}
336
	else {
337
	    *s++ = *filename++;
338
	}
339
    }
340
    *s = '\0';
341
    dirv[dirvp] = s;
342
    if (striplast)
343
	dirvp--;
344
    if (dirvp < 0)
345
	return;
346
347
    strcpy(buf, "mkdir");
348
    s = buf;
349
    for (i=0; i<=dirvp; i++) {
350
	struct stat sbuf;
351
352
	if (stat(tmpbuf, &sbuf) && errno == ENOENT) {
353
	    while (*s) s++;
354
	    *s++ = ' ';
355
	    strcpy(s, tmpbuf);
356
	}
357
	*dirv[i] = '/';
358
    }
339
    }
359
    if (s != buf)
340
360
	system(buf);
341
    strcpy(buf, "/bin/mkdir -p ");
342
    if (strlcat(buf, tmpbuf, sizeof(buf)) >= sizeof(buf))
343
	fatal2("buffer too small to hold %.20s...\n", tmpbuf);
344
345
    if (system(buf))
346
	pfatal2("%.40s failed", buf);
361
}
347
}
362
348
363
/* Make filenames more reasonable. */
349
/* Make filenames more reasonable. */
Lines 374-380 Link Here
374
    char tmpbuf[200];
360
    char tmpbuf[200];
375
    int sleading = strip_leading;
361
    int sleading = strip_leading;
376
362
377
    if (!at)
363
    if (!at || *at == '\0')
378
	return Nullch;
364
	return Nullch;
379
    while (isspace((unsigned char)*at))
365
    while (isspace((unsigned char)*at))
380
	at++;
366
	at++;
Lines 410-426 Link Here
410
396
411
    if (stat(name, &filestat) && !assume_exists) {
397
    if (stat(name, &filestat) && !assume_exists) {
412
	char *filebase = basename(name);
398
	char *filebase = basename(name);
413
	int pathlen = filebase - name;
399
	char *filedir = dirname(name);
414
415
	/* Put any leading path into `tmpbuf'.  */
416
	strncpy(tmpbuf, name, pathlen);
417
400
418
#define try(f, a1, a2) (Sprintf(tmpbuf + pathlen, f, a1, a2), stat(tmpbuf, &filestat) == 0)
401
#define try(f, a1, a2, a3) (Snprintf(tmpbuf, sizeof(tmpbuf), f, a1, a2, a3), \
419
	if (   try("RCS/%s%s", filebase, RCSSUFFIX)
402
			    stat(tmpbuf, &filestat) == 0)
420
	    || try("RCS/%s%s", filebase,        "")
403
	if (   try("%s/RCS/%s%s", filedir, filebase, RCSSUFFIX)
421
	    || try(    "%s%s", filebase, RCSSUFFIX)
404
	    || try("%s/RCS/%s%s", filedir, filebase,        "")
422
	    || try("SCCS/%s%s", SCCSPREFIX, filebase)
405
	    || try(    "%s/%s%s", filedir, filebase, RCSSUFFIX)
423
	    || try(     "%s%s", SCCSPREFIX, filebase))
406
	    || try("%s/SCCS/%s%s", filedir, SCCSPREFIX, filebase)
407
	    || try(     "%s/%s%s", filedir, SCCSPREFIX, filebase))
424
	  return name;
408
	  return name;
425
	free(name);
409
	free(name);
426
	name = Nullch;
410
	name = Nullch;
(-)gnu/usr.bin/patch/util.h (+2 lines)
Lines 86-88 Link Here
86
void ignore_signals();
86
void ignore_signals();
87
void makedirs();
87
void makedirs();
88
char *basename();
88
char *basename();
89
char *dirname();
90
(-)gnu/usr.bin/patch/version.c (+4 lines)
Lines 13-19 Link Here
13
#include "patchlevel.h"
13
#include "patchlevel.h"
14
#include "version.h"
14
#include "version.h"
15
15
16
#ifdef __GNUC__
17
void my_exit() __attribute__((noreturn));
18
#else
16
void my_exit();
19
void my_exit();
20
#endif
17
21
18
/* Print out the version number and die. */
22
/* Print out the version number and die. */

Return to bug 19642