diff options
| author | Kyle Evans <kevans@FreeBSD.org> | 2019-11-04 03:07:01 +0000 |
|---|---|---|
| committer | Kyle Evans <kevans@FreeBSD.org> | 2019-11-04 03:07:01 +0000 |
| commit | 50dacbf6c2a3d32f7e3f20ca98cda23f38817e7f (patch) | |
| tree | 437dcfd9f3bec678f1401ffc4a37a774a403f349 /usr.bin/patch/pch.c | |
| parent | 69fac7c3af9903ba2e6bedd29a969667b0367133 (diff) | |
Notes
Diffstat (limited to 'usr.bin/patch/pch.c')
| -rw-r--r-- | usr.bin/patch/pch.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c index 50e1604b9b92d..24e3eea5f297c 100644 --- a/usr.bin/patch/pch.c +++ b/usr.bin/patch/pch.c @@ -70,6 +70,8 @@ static LINENUM p_bfake = -1; /* beg of faked up lines */ static FILE *pfp = NULL; /* patch file pointer */ static char *bestguess = NULL; /* guess at correct filename */ +char *source_file; + static void grow_hunkmax(void); static int intuit_diff_type(void); static void next_intuit_at(off_t, LINENUM); @@ -218,7 +220,12 @@ there_is_another_patch(void) bestguess = xstrdup(buf); filearg[0] = fetchname(buf, &exists, 0); } - if (!exists) { + /* + * fetchname can now return buf = NULL, exists = true, to + * indicate to the caller that /dev/null was specified. Retain + * previous behavior for now until this can be better evaluted. + */ + if (filearg[0] == NULL || !exists) { int def_skip = *bestguess == '\0'; ask("No file found--skip this patch? [%c] ", def_skip ? 'y' : 'n'); @@ -403,6 +410,24 @@ scan_exit: names[OLD_FILE] = names[NEW_FILE]; names[NEW_FILE] = tmp; } + + /* Invalidated */ + free(source_file); + source_file = NULL; + + if (retval != 0) { + /* + * If we've successfully determined a diff type, stored in + * retval, path == NULL means _PATH_DEVNULL if exists is set. + * Explicitly specify it here to make it easier to detect later + * on that we're actually creating a file and not that we've + * just goofed something up. + */ + if (names[OLD_FILE].path != NULL) + source_file = xstrdup(names[OLD_FILE].path); + else if (names[OLD_FILE].exists) + source_file = xstrdup(_PATH_DEVNULL); + } if (filearg[0] == NULL) { if (posix) filearg[0] = posix_name(names, ok_to_create_file); |
