* in cases involving special characters. Here a C version.
*/
#include <stdio.h>
+#ifdef HAVE_STDIO_EXT_H
+# include <stdio_ext.h>
+#endif
+#ifndef HAVE___FPURGE
+# ifdef HAVE_FPURGE
+# define HAVE___FPURGE 1
+# define __fpurge fpurge
+# endif
+#endif
#include <string.h>
#include <stdlib.h>
#include <errno.h>
fflush(stdout);
if ((c = fgetc(stdin)) == EOF) {
buf[0] = 'n';
- clearerr(stdin); errno = 0;
printf("n\n");
}
else {
buf[0] = c;
- if (c != '\n' && tty_cbreak) /* no purge necessary */
+ if (c != '\n' && tty_cbreak) {
+#ifdef HAVE___FPURGE
+ /* Possibly purge a multi-byte character; or do a
+ required purge of the rest of the line (including
+ the newline) if the tty has been put back in
+ canonical mode (for example by a shell after a
+ SIGTSTP signal). */
+ __fpurge(stdin);
+#endif
printf("\n");
+ }
else if (c != '\n')
while ((c = fgetc(stdin)) != '\n' && c != EOF);
}
buf[1] = '\0';
if (rpmatch(buf) == RPMATCH_YES)
return 0;
- else
- return 1;
+
+ return 1;
}
static int do_symlink(char *from, char *to, char *s, int verbose, int noact,
return 2;
}
target[sb.st_size] = '\0';
- if (string_replace(from, to, target, target, &newname))
+ if (string_replace(from, to, target, target, &newname) != 0)
ret = 0;
if (ret == 1 && (nooverwrite || interactive) && lstat(newname, &sb) != 0)
if (!noact && 0 > unlink(s)) {
warn(_("%s: unlink failed"), s);
ret = 2;
- } else if (!noact && symlink(newname, s) != 0) {
+ }
+ else if (!noact && symlink(newname, s) != 0) {
warn(_("%s: symlinking to %s failed"), s, newname);
ret = 2;
}
}
if (verbose && (noact || ret == 1))
- if (verbose)
- printf("%s: `%s' -> `%s'\n", s, target, newname);
+ printf("%s: `%s' -> `%s'\n", s, target, newname);
free(newname);
free(target);
return ret;
file = strrchr(s, '/');
if (file == NULL)
file = s;
- if (string_replace(from, to, file, s, &newname))
+ if (string_replace(from, to, file, s, &newname) != 0)
return 0;
if ((nooverwrite || interactive) && access(newname, F_OK) != 0)
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
- atexit(close_stdout);
+ close_stdout_atexit();
while ((c = getopt_long(argc, argv, "vsVhnoi", longopts, NULL)) != -1)
switch (c) {
case 's':
do_rename = do_symlink;
break;
+
case 'V':
- printf(UTIL_LINUX_VERSION);
- return EXIT_SUCCESS;
+ print_version(EXIT_SUCCESS);
case 'h':
usage();
default: