1 /* Invoke the system diff tool to compare two strings.
2 Copyright (C) 2016-2020 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <support/run_diff.h>
24 #include <support/check.h>
25 #include <support/support.h>
26 #include <support/temp_file.h>
27 #include <support/xunistd.h>
31 write_to_temp_file (const char *prefix
, const char *str
)
33 char *template = xasprintf ("run_diff-%s", prefix
);
35 int fd
= create_temp_file (template, &name
);
36 TEST_VERIFY_EXIT (fd
>= 0);
38 xwrite (fd
, str
, strlen (str
));
44 support_run_diff (const char *left_label
, const char *left
,
45 const char *right_label
, const char *right
)
47 /* Ensure that the diff command output is ordered properly with
49 TEST_VERIFY_EXIT (fflush (stdout
) == 0);
51 char *left_path
= write_to_temp_file ("left-diff", left
);
52 char *right_path
= write_to_temp_file ("right-diff", right
);
57 execlp ("diff", "diff", "-u",
58 "--label", left_label
, "--label", right_label
,
59 "--", left_path
, right_path
,
66 xwaitpid (pid
, &status
, 0);
67 if (!WIFEXITED (status
) || WEXITSTATUS (status
) != 1)
68 printf ("warning: could not run diff, exit status: %d\n"
71 status
, left_label
, left
, right_label
, right
);