Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/editors/patch.c


Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/editors/patch.c

    r3232 r3621  
    346346// state 2: In hunk: counting initial context lines
    347347// state 3: In hunk: getting body
     348// Like GNU patch, we don't require a --- line before the +++, and
     349// also allow the --- after the +++ line.
    348350
    349351int patch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     
    371373        }
    372374    }
    373     if (argv[0]) {
    374         oldname = xstrdup(argv[0]);
    375         newname = xstrdup(argv[0]);
    376     }
    377375
    378376    // Loop through the lines in the patch
     
    413411
    414412        // Open a new file?
    415         if (!strncmp("--- ", patchline, 4) || !strncmp("+++ ", patchline, 4)) {
     413        if (is_prefixed_with(patchline, "--- ") || is_prefixed_with(patchline, "+++ ")) {
    416414            char *s, **name = reverse ? &newname : &oldname;
    417415            int i;
     
    445443        // Start a new hunk?  Usually @@ -oldline,oldlen +newline,newlen @@
    446444        // but a missing ,value means the value is 1.
    447         } else if (state == 1 && !strncmp("@@ -", patchline, 4)) {
     445        } else if (state == 1 && is_prefixed_with(patchline, "@@ -")) {
    448446            int i;
    449447            char *s = patchline+4;
     
    463461            state = 2;
    464462
     463            // If the --- line is missing or malformed, either oldname
     464            // or (for -R) newname could be NULL -- but not both.  Like
     465            // GNU patch, proceed based on the +++ line, and avoid SEGVs.
     466            if (!oldname)
     467                oldname = xstrdup("MISSING_FILENAME");
     468            if (!newname)
     469                newname = xstrdup("MISSING_FILENAME");
     470
    465471            // If this is the first hunk, open the file.
    466472            if (TT.filein == -1) {
     
    477483                if (!strcmp(name, "/dev/null") || !(reverse ? oldsum : newsum)) {
    478484                    name = reverse ? newname : oldname;
    479                     empty++;
     485                    empty = 1;
    480486                }
    481487
    482                 // handle -p path truncation.
     488                // Handle -p path truncation.
    483489                for (i = 0, s = name; *s;) {
    484490                    if ((option_mask32 & FLAG_PATHLEN) && TT.prefix == i)
     
    491497                    name = s;
    492498                }
     499                // If "patch FILE_TO_PATCH", completely ignore name from patch
     500                if (argv[0])
     501                    name = argv[0];
    493502
    494503                if (empty) {
Note: See TracChangeset for help on using the changeset viewer.