2 * Copyright 1986, Larry Wall
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following condition is met:
6 * 1. Redistributions of source code must retain the above copyright notice,
7 * this condition and the following disclaimer.
9 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
10 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
12 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
13 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
14 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
15 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
16 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
17 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
18 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
21 * patch - a program to apply diffs to original files
23 * -C option added in 1998, original code by Marc Espie, based on FreeBSD
26 * $OpenBSD: patch.c,v 1.50 2012/05/15 19:32:02 millert Exp $
31 #include <sys/types.h>
46 #include "backupfile.h"
47 #include "pathnames.h"
49 mode_t filemode = 0644;
51 char *buf; /* general purpose buffer */
52 size_t buf_size; /* size of the general purpose buffer */
54 bool using_plan_a = true; /* try to keep everything in memory */
55 bool out_of_mem = false; /* ran out of memory in plan a */
59 char *filearg[MAXFILEC];
60 bool ok_to_create_file = false;
62 char *origprae = NULL;
67 bool toutkeep = false;
68 bool trejkeep = false;
69 bool warn_on_invalid_line;
70 bool last_line_missing_eol;
80 bool noreverse = false;
81 bool skip_rest_of_patch = false;
83 bool canonicalize = false;
84 bool check_only = false;
86 char *revision = NULL; /* prerequisite revision, if any */
87 LINENUM input_lines = 0; /* how long is input file in lines */
88 int posix = 0; /* strict POSIX mode? */
90 static void reinitialize_almost_everything(void);
91 static void get_some_switches(void);
92 static LINENUM locate_hunk(LINENUM);
93 static void abort_context_hunk(void);
94 static void rej_line(int, LINENUM);
95 static void abort_hunk(void);
96 static void apply_hunk(LINENUM);
97 static void init_output(const char *);
98 static void init_reject(const char *);
99 static void copy_till(LINENUM, bool);
100 static bool spew_output(void);
101 static void dump_line(LINENUM, bool);
102 static bool patch_match(LINENUM, LINENUM, LINENUM);
103 static bool similar(const char *, const char *, int);
104 static void usage(void);
106 /* true if -E was specified on command line. */
107 static bool remove_empty_files = false;
109 /* true if -R was specified on command line. */
110 static bool reverse_flag_specified = false;
112 /* buffer holding the name of the rejected patch file. */
113 static char rejname[NAME_MAX + 1];
115 /* how many input lines have been irretractibly output */
116 static LINENUM last_frozen_line = 0;
118 static int Argc; /* guess */
120 static int Argc_last; /* for restarting plan_b */
121 static char **Argv_last;
123 static FILE *ofp = NULL; /* output file pointer */
124 static FILE *rejfp = NULL; /* reject file pointer */
126 static int filec = 0; /* how many file arguments? */
127 static LINENUM last_offset = 0;
128 static LINENUM maxfuzz = 2;
130 /* patch using ifdef, ifndef, etc. */
131 static bool do_defines = false;
133 static char if_defined[128];
135 static char not_defined[128];
137 static const char else_defined[] = "#else\n";
139 static char end_defined[128];
142 /* Apply a set of diffs as appropriate. */
145 main(int argc, char *argv[])
147 int error = 0, hunk, failed, i, fd;
149 LINENUM where = 0, newwhere, fuzz, mymaxfuzz;
155 for (i = 0; i < MAXFILEC; i++)
158 buf_size = INITLINELEN;
159 buf = malloc((unsigned)(buf_size));
161 fatal("out of memory\n");
163 /* Cons up the names of the temporary files. */
164 if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0')
166 for (i = strlen(tmpdir) - 1; i > 0 && tmpdir[i] == '/'; i--)
169 if (asprintf(&TMPOUTNAME, "%.*s/patchoXXXXXXXXXX", i, tmpdir) == -1)
170 fatal("cannot allocate memory");
171 if ((fd = mkstemp(TMPOUTNAME)) < 0)
172 pfatal("can't create %s", TMPOUTNAME);
175 if (asprintf(&TMPINNAME, "%.*s/patchiXXXXXXXXXX", i, tmpdir) == -1)
176 fatal("cannot allocate memory");
177 if ((fd = mkstemp(TMPINNAME)) < 0)
178 pfatal("can't create %s", TMPINNAME);
181 if (asprintf(&TMPREJNAME, "%.*s/patchrXXXXXXXXXX", i, tmpdir) == -1)
182 fatal("cannot allocate memory");
183 if ((fd = mkstemp(TMPREJNAME)) < 0)
184 pfatal("can't create %s", TMPREJNAME);
187 if (asprintf(&TMPPATNAME, "%.*s/patchpXXXXXXXXXX", i, tmpdir) == -1)
188 fatal("cannot allocate memory");
189 if ((fd = mkstemp(TMPPATNAME)) < 0)
190 pfatal("can't create %s", TMPPATNAME);
193 v = getenv("SIMPLE_BACKUP_SUFFIX");
195 simple_backup_suffix = v;
197 simple_backup_suffix = ORIGEXT;
204 if (backup_type == none) {
205 if ((v = getenv("PATCH_VERSION_CONTROL")) == NULL)
206 v = getenv("VERSION_CONTROL");
207 if (v != NULL || !posix)
208 backup_type = get_version(v); /* OK to pass NULL. */
211 /* make sure we clean up /tmp in case of disaster */
215 for (open_patch_file(filearg[1]); there_is_another_patch();
216 reinitialize_almost_everything()) {
217 /* for each patch in patch file */
221 warn_on_invalid_line = true;
224 outname = savestr(filearg[0]);
226 /* for ed script just up and do it and exit */
227 if (diff_type == ED_DIFF) {
231 /* initialize the patched file */
232 if (!skip_rest_of_patch)
233 init_output(TMPOUTNAME);
235 /* initialize reject file */
236 init_reject(TMPREJNAME);
238 /* find out where all the lines are */
239 if (!skip_rest_of_patch)
240 scan_input(filearg[0]);
243 * from here on, open no standard i/o files, because
244 * malloc might misfire and we can't catch it easily
247 /* apply each hunk of patch */
251 while (another_hunk()) {
254 mymaxfuzz = pch_context();
255 if (maxfuzz < mymaxfuzz)
257 if (!skip_rest_of_patch) {
259 where = locate_hunk(fuzz);
260 if (hunk == 1 && where == 0 && !force) {
261 /* dwim for reversed patch? */
264 say("Not enough memory to try swapped hunk! Assuming unswapped.\n");
269 where = locate_hunk(fuzz);
271 /* didn't find it swapped */
273 /* put it back to normal */
274 fatal("lost hunk on alloc error!\n");
276 } else if (noreverse) {
278 /* put it back to normal */
279 fatal("lost hunk on alloc error!\n");
281 say("Ignoring previously applied (or reversed) patch.\n");
282 skip_rest_of_patch = true;
285 say("%seversed (or previously applied) patch detected! %s -R.",
286 reverse ? "R" : "Unr",
287 reverse ? "Assuming" : "Ignoring");
289 ask("%seversed (or previously applied) patch detected! %s -R? [y] ",
290 reverse ? "R" : "Unr",
291 reverse ? "Assume" : "Ignore");
293 ask("Apply anyway? [n] ");
295 skip_rest_of_patch = true;
299 /* put it back to normal */
300 fatal("lost hunk on alloc error!\n");
304 } while (!skip_rest_of_patch && where == 0 &&
305 ++fuzz <= mymaxfuzz);
307 if (skip_rest_of_patch) { /* just got decided */
308 if (ferror(ofp) || fclose(ofp)) {
309 say("Error writing %s\n",
316 newwhere = pch_newfirst() + last_offset;
317 if (skip_rest_of_patch) {
321 say("Hunk #%d ignored at %ld.\n",
323 } else if (where == 0) {
327 say("Hunk #%d failed at %ld.\n",
332 say("Hunk #%d succeeded at %ld",
335 say(" with fuzz %ld", fuzz);
337 say(" (offset %ld line%s)",
339 last_offset == 1L ? "" : "s");
345 if (out_of_mem && using_plan_a) {
348 say("\n\nRan out of memory using Plan A--trying again...\n\n");
358 fatal("Internal error: hunk should not be 0\n");
360 /* finish spewing out the new file */
361 if (!skip_rest_of_patch && !spew_output()) {
362 say("Can't write %s\n", TMPOUTNAME);
366 /* and put the output where desired */
368 if (!skip_rest_of_patch) {
370 char *realout = outname;
373 if (move_file(TMPOUTNAME, outname) < 0) {
375 realout = TMPOUTNAME;
376 chmod(TMPOUTNAME, filemode);
378 chmod(outname, filemode);
380 if (remove_empty_files &&
381 stat(realout, &statbuf) == 0 &&
382 statbuf.st_size == 0) {
384 say("Removing %s (empty after patching).\n",
390 if (ferror(rejfp) || fclose(rejfp)) {
391 say("Error writing %s\n", rejname);
397 if (*rejname == '\0') {
398 if (strlcpy(rejname, outname,
399 sizeof(rejname)) >= sizeof(rejname))
400 fatal("filename %s is too long\n", outname);
401 if (strlcat(rejname, REJEXT,
402 sizeof(rejname)) >= sizeof(rejname))
403 fatal("filename %s is too long\n", outname);
406 say("%d out of %d hunks %s--saving rejects to %s\n",
407 failed, hunk, skip_rest_of_patch ? "ignored" : "failed", rejname);
409 say("%d out of %d hunks %s\n",
410 failed, hunk, skip_rest_of_patch ? "ignored" : "failed");
411 if (!check_only && move_file(TMPREJNAME, rejname) < 0)
424 /* Prepare to find the next patch to do in the patch file. */
427 reinitialize_almost_everything(void)
433 last_frozen_line = 0;
450 reverse = reverse_flag_specified;
451 skip_rest_of_patch = false;
456 /* Process switches and filenames. */
459 get_some_switches(void)
461 const char *options = "b::B:cCd:D:eEfF:i:lnNo:p:r:RstuvV:x:z:";
462 static struct option longopts[] = {
463 {"backup", no_argument, 0, 'b'},
464 {"batch", no_argument, 0, 't'},
465 {"check", no_argument, 0, 'C'},
466 {"context", no_argument, 0, 'c'},
467 {"debug", required_argument, 0, 'x'},
468 {"directory", required_argument, 0, 'd'},
469 {"ed", no_argument, 0, 'e'},
470 {"force", no_argument, 0, 'f'},
471 {"forward", no_argument, 0, 'N'},
472 {"fuzz", required_argument, 0, 'F'},
473 {"ifdef", required_argument, 0, 'D'},
474 {"input", required_argument, 0, 'i'},
475 {"ignore-whitespace", no_argument, 0, 'l'},
476 {"normal", no_argument, 0, 'n'},
477 {"output", required_argument, 0, 'o'},
478 {"prefix", required_argument, 0, 'B'},
479 {"quiet", no_argument, 0, 's'},
480 {"reject-file", required_argument, 0, 'r'},
481 {"remove-empty-files", no_argument, 0, 'E'},
482 {"reverse", no_argument, 0, 'R'},
483 {"silent", no_argument, 0, 's'},
484 {"strip", required_argument, 0, 'p'},
485 {"suffix", required_argument, 0, 'z'},
486 {"unified", no_argument, 0, 'u'},
487 {"version", no_argument, 0, 'v'},
488 {"version-control", required_argument, 0, 'V'},
489 {"posix", no_argument, &posix, 1},
499 optreset = optind = 1;
500 while ((ch = getopt_long(Argc, Argv, options, longopts, NULL)) != -1) {
503 if (backup_type == none)
504 backup_type = numbered_existing;
508 say("Warning, the ``-b suffix'' option has been"
509 " obsoleted by the -z option.\n");
512 /* must directly follow 'b' case for backwards compat */
513 simple_backup_suffix = savestr(optarg);
516 origprae = savestr(optarg);
519 diff_type = CONTEXT_DIFF;
525 if (chdir(optarg) < 0)
526 pfatal("can't cd to %s", optarg);
530 if (!isalpha((unsigned char)*optarg) && *optarg != '_')
531 fatal("argument to -D is not an identifier\n");
532 snprintf(if_defined, sizeof if_defined,
533 "#ifdef %s\n", optarg);
534 snprintf(not_defined, sizeof not_defined,
535 "#ifndef %s\n", optarg);
536 snprintf(end_defined, sizeof end_defined,
537 "#endif /* %s */\n", optarg);
543 remove_empty_files = true;
549 maxfuzz = atoi(optarg);
552 if (++filec == MAXFILEC)
553 fatal("too many file arguments\n");
554 filearg[filec] = savestr(optarg);
560 diff_type = NORMAL_DIFF;
566 outname = savestr(optarg);
569 strippath = atoi(optarg);
572 if (strlcpy(rejname, optarg,
573 sizeof(rejname)) >= sizeof(rejname))
574 fatal("argument for -r is too long\n");
578 reverse_flag_specified = true;
587 diff_type = UNI_DIFF;
593 backup_type = get_version(optarg);
597 debug = atoi(optarg);
610 filearg[0] = savestr(*Argv++);
613 if (++filec == MAXFILEC)
614 fatal("too many file arguments\n");
615 filearg[filec] = savestr(*Argv++);
620 if (getenv("POSIXLY_CORRECT") != NULL)
628 "usage: patch [-bCcEeflNnRstuv] [-B backup-prefix] [-D symbol] [-d directory]\n"
629 " [-F max-fuzz] [-i patchfile] [-o out-file] [-p strip-count]\n"
630 " [-r rej-name] [-V t | nil | never] [-x number] [-z backup-ext]\n"
631 " [--posix] [origfile [patchfile]]\n"
632 " patch <patchfile\n");
633 my_exit(EXIT_SUCCESS);
637 * Attempt to find the right place to apply this hunk of patch.
640 locate_hunk(LINENUM fuzz)
642 LINENUM first_guess = pch_first() + last_offset;
644 LINENUM pat_lines = pch_ptrn_lines();
645 LINENUM max_pos_offset = input_lines - first_guess - pat_lines + 1;
646 LINENUM max_neg_offset = first_guess - last_frozen_line - 1 + pch_context();
648 if (pat_lines == 0) { /* null range matches always */
649 if (verbose && fuzz == 0 && (diff_type == CONTEXT_DIFF
650 || diff_type == NEW_CONTEXT_DIFF
651 || diff_type == UNI_DIFF)) {
652 say("Empty context always matches.\n");
654 return (first_guess);
656 if (max_neg_offset >= first_guess) /* do not try lines < 0 */
657 max_neg_offset = first_guess - 1;
658 if (first_guess <= input_lines && patch_match(first_guess, 0, fuzz))
660 for (offset = 1; ; offset++) {
661 bool check_after = (offset <= max_pos_offset);
662 bool check_before = (offset <= max_neg_offset);
664 if (check_after && patch_match(first_guess, offset, fuzz)) {
667 say("Offset changing from %ld to %ld\n",
668 last_offset, offset);
670 last_offset = offset;
671 return first_guess + offset;
672 } else if (check_before && patch_match(first_guess, -offset, fuzz)) {
675 say("Offset changing from %ld to %ld\n",
676 last_offset, -offset);
678 last_offset = -offset;
679 return first_guess - offset;
680 } else if (!check_before && !check_after)
685 /* We did not find the pattern, dump out the hunk so they can handle it. */
688 abort_context_hunk(void)
691 const LINENUM pat_end = pch_end();
693 * add in last_offset to guess the same as the previous successful
696 const LINENUM oldfirst = pch_first() + last_offset;
697 const LINENUM newfirst = pch_newfirst() + last_offset;
698 const LINENUM oldlast = oldfirst + pch_ptrn_lines() - 1;
699 const LINENUM newlast = newfirst + pch_repl_lines() - 1;
700 const char *stars = (diff_type >= NEW_CONTEXT_DIFF ? " ****" : "");
701 const char *minuses = (diff_type >= NEW_CONTEXT_DIFF ? " ----" : " -----");
703 fprintf(rejfp, "***************\n");
704 for (i = 0; i <= pat_end; i++) {
705 switch (pch_char(i)) {
707 if (oldlast < oldfirst)
708 fprintf(rejfp, "*** 0%s\n", stars);
709 else if (oldlast == oldfirst)
710 fprintf(rejfp, "*** %ld%s\n", oldfirst, stars);
712 fprintf(rejfp, "*** %ld,%ld%s\n", oldfirst,
716 if (newlast < newfirst)
717 fprintf(rejfp, "--- 0%s\n", minuses);
718 else if (newlast == newfirst)
719 fprintf(rejfp, "--- %ld%s\n", newfirst, minuses);
721 fprintf(rejfp, "--- %ld,%ld%s\n", newfirst,
725 fprintf(rejfp, "%s", pfetch(i));
731 fprintf(rejfp, "%c %s", pch_char(i), pfetch(i));
734 fatal("fatal internal error in abort_context_hunk\n");
740 rej_line(int ch, LINENUM i)
743 const char *line = pfetch(i);
747 fprintf(rejfp, "%c%s", ch, line);
748 if (len == 0 || line[len-1] != '\n')
749 fprintf(rejfp, "\n\\ No newline at end of file\n");
757 const LINENUM pat_end = pch_end();
758 const LINENUM oldfirst = pch_first() + last_offset;
759 const LINENUM newfirst = pch_newfirst() + last_offset;
761 if (diff_type != UNI_DIFF) {
762 abort_context_hunk();
766 for (i = 0; i <= pat_end; i++) {
767 if (pch_char(i) == '=') {
773 fprintf(rejfp, "malformed hunk: no split found\n");
778 fprintf(rejfp, "@@ -%ld,%ld +%ld,%ld @@\n",
779 pch_ptrn_lines() ? oldfirst : 0,
780 pch_ptrn_lines(), newfirst, pch_repl_lines());
781 while (i < split || j <= pat_end) {
782 ch1 = i < split ? pch_char(i) : -1;
783 ch2 = j <= pat_end ? pch_char(j) : -1;
787 } else if (ch1 == ' ' && ch2 == ' ') {
791 } else if (ch1 == '!' && ch2 == '!') {
792 while (i < split && ch1 == '!') {
795 ch1 = i < split ? pch_char(i) : -1;
797 while (j <= pat_end && ch2 == '!') {
800 ch2 = j <= pat_end ? pch_char(j) : -1;
802 } else if (ch1 == '*') {
804 } else if (ch2 == '+' || ch2 == ' ') {
808 fprintf(rejfp, "internal error on (%ld %ld %ld)\n",
817 /* We found where to apply it (we hope), so do it. */
820 apply_hunk(LINENUM where)
823 const LINENUM lastline = pch_ptrn_lines();
824 LINENUM new = lastline + 1;
829 int def_state = OUTSIDE;
830 const LINENUM pat_end = pch_end();
833 while (pch_char(new) == '=' || pch_char(new) == '\n')
836 while (old <= lastline) {
837 if (pch_char(old) == '-') {
838 copy_till(where + old - 1, false);
840 if (def_state == OUTSIDE) {
841 fputs(not_defined, ofp);
842 def_state = IN_IFNDEF;
843 } else if (def_state == IN_IFDEF) {
844 fputs(else_defined, ofp);
847 fputs(pfetch(old), ofp);
851 } else if (new > pat_end) {
853 } else if (pch_char(new) == '+') {
854 copy_till(where + old - 1, false);
856 if (def_state == IN_IFNDEF) {
857 fputs(else_defined, ofp);
859 } else if (def_state == OUTSIDE) {
860 fputs(if_defined, ofp);
861 def_state = IN_IFDEF;
864 fputs(pfetch(new), ofp);
866 } else if (pch_char(new) != pch_char(old)) {
867 say("Out-of-sync patch, lines %ld,%ld--mangled text or line numbers, maybe?\n",
868 pch_hunk_beg() + old,
869 pch_hunk_beg() + new);
871 say("oldchar = '%c', newchar = '%c'\n",
872 pch_char(old), pch_char(new));
875 } else if (pch_char(new) == '!') {
876 copy_till(where + old - 1, false);
878 fputs(not_defined, ofp);
879 def_state = IN_IFNDEF;
881 while (pch_char(old) == '!') {
883 fputs(pfetch(old), ofp);
889 fputs(else_defined, ofp);
892 while (pch_char(new) == '!') {
893 fputs(pfetch(new), ofp);
897 if (pch_char(new) != ' ')
898 fatal("Internal error: expected ' '\n");
901 if (do_defines && def_state != OUTSIDE) {
902 fputs(end_defined, ofp);
907 if (new <= pat_end && pch_char(new) == '+') {
908 copy_till(where + old - 1, false);
910 if (def_state == OUTSIDE) {
911 fputs(if_defined, ofp);
912 def_state = IN_IFDEF;
913 } else if (def_state == IN_IFNDEF) {
914 fputs(else_defined, ofp);
918 while (new <= pat_end && pch_char(new) == '+') {
919 fputs(pfetch(new), ofp);
923 if (do_defines && def_state != OUTSIDE) {
924 fputs(end_defined, ofp);
932 init_output(const char *name)
934 ofp = fopen(name, "w");
936 pfatal("can't create %s", name);
940 * Open a file to put hunks we can't locate.
943 init_reject(const char *name)
945 rejfp = fopen(name, "w");
947 pfatal("can't create %s", name);
951 * Copy input file to output, up to wherever hunk is to be applied.
952 * If endoffile is true, treat the last line specially since it may
956 copy_till(LINENUM lastline, bool endoffile)
958 if (last_frozen_line > lastline)
959 fatal("misordered hunks! output would be garbled\n");
960 while (last_frozen_line < lastline) {
961 if (++last_frozen_line == lastline && endoffile)
962 dump_line(last_frozen_line, !last_line_missing_eol);
964 dump_line(last_frozen_line, true);
969 * Finish copying the input file to the output file.
978 say("il=%ld lfl=%ld\n", input_lines, last_frozen_line);
981 copy_till(input_lines, true); /* dump remainder of file */
982 rv = ferror(ofp) == 0 && fclose(ofp) == 0;
988 * Copy one line from input to output.
991 dump_line(LINENUM line, bool write_newline)
998 /* Note: string is not NUL terminated. */
999 for (; *s != '\n'; s++)
1006 * Does the patch pattern match at line base+offset?
1009 patch_match(LINENUM base, LINENUM offset, LINENUM fuzz)
1011 LINENUM pline = 1 + fuzz;
1013 LINENUM pat_lines = pch_ptrn_lines() - fuzz;
1014 const char *ilineptr;
1015 const char *plineptr;
1018 for (iline = base + offset + fuzz; pline <= pat_lines; pline++, iline++) {
1019 ilineptr = ifetch(iline, offset >= 0);
1020 if (ilineptr == NULL)
1022 plineptr = pfetch(pline);
1023 plinelen = pch_line_len(pline);
1025 if (!similar(ilineptr, plineptr, plinelen))
1027 } else if (strnNE(ilineptr, plineptr, plinelen))
1029 if (iline == input_lines) {
1031 * We are looking at the last line of the file.
1032 * If the file has no eol, the patch line should
1033 * not have one either and vice-versa. Note that
1036 if (last_line_missing_eol) {
1037 if (plineptr[plinelen - 1] == '\n')
1040 if (plineptr[plinelen - 1] != '\n')
1049 * Do two lines match with canonicalized white space?
1052 similar(const char *a, const char *b, int len)
1055 if (isspace((unsigned char)*b)) { /* whitespace (or \n) to match? */
1056 if (!isspace((unsigned char)*a)) /* no corresponding whitespace? */
1058 while (len && isspace((unsigned char)*b) && *b != '\n')
1059 b++, len--; /* skip pattern whitespace */
1060 while (isspace((unsigned char)*a) && *a != '\n')
1061 a++; /* skip target whitespace */
1062 if (*a == '\n' || *b == '\n')
1063 return (*a == *b); /* should end in sync */
1064 } else if (*a++ != *b++) /* match non-whitespace chars */
1067 len--; /* probably not necessary */
1069 return true; /* actually, this is not reached */
1070 /* since there is always a \n */