From 48b69beda9d38ea8d4211a9f8e037dc1851cc5f9 Mon Sep 17 00:00:00 2001 From: merakor Date: Fri, 24 Jul 2020 09:08:10 +0000 Subject: rename binary programs FossilOrigin-Name: f404639f07097134f93aa22cc5583ff73a6cd281aa4b1bbfd10053ebd97d7bf4 --- bin/cpt-readlink.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ bin/cpt-stat.c | 41 +++++++++++++++++++++++++++++++++++++++++ bin/kiss-readlink.c | 47 ----------------------------------------------- bin/kiss-stat.c | 41 ----------------------------------------- 4 files changed, 88 insertions(+), 88 deletions(-) create mode 100644 bin/cpt-readlink.c create mode 100644 bin/cpt-stat.c delete mode 100644 bin/kiss-readlink.c delete mode 100644 bin/kiss-stat.c diff --git a/bin/cpt-readlink.c b/bin/cpt-readlink.c new file mode 100644 index 0000000..cc6c8ff --- /dev/null +++ b/bin/cpt-readlink.c @@ -0,0 +1,47 @@ +/* kiss-readlink --- a utility replacement for readlink + * See LICENSE for copyright information. + * + * This is basically a 'readlink -f' command. + */ +#include +#include +#include +#include +#include + +#define DIR_MAX PATH_MAX - NAME_MAX - 1 + + +char *realpath(const char *path, char *resolved_path); + +int +main(int argc, char *argv[]) +{ + + char buf[PATH_MAX]; + + /* We are going to use these if the file doesn't exist, but we can still + * use directories above the file. We are using dname and bname so that + * they don't clash with the functions with the same name. + */ + char dname[DIR_MAX]; /* directory name */ + char bname[NAME_MAX]; /* base name */ + sprintf(bname, "%s", (basename(argv[1]))); + + if (argc != 2 || strcmp(argv[1], "--help") == 0) { + fprintf(stderr, "usage: %s [file]\n", argv[0]); + return 1; + } + + if (!realpath(argv[1], buf)) { + + if (!realpath(dirname(argv[1]), dname)) { + perror(argv[0]); + return 1; + } + sprintf(buf, "%s/%s", dname, bname); + } + + printf("%s\n", buf); + return 0; +} diff --git a/bin/cpt-stat.c b/bin/cpt-stat.c new file mode 100644 index 0000000..4380503 --- /dev/null +++ b/bin/cpt-stat.c @@ -0,0 +1,41 @@ +/* kiss-stat --- a utility for getting the user name of file owner + * See LICENSE for copyright information + * + * The reason this simple tool exists is because 'stat' is not + * portable and ls is not exactly stable enough for scripting. + * This program is for outputting the owner name, and that's it. + */ + +#include +#include +#include +#include + +struct passwd *pw; +struct stat sb; + +int +main (int argc, char *argv[]) +{ + /* Exit if no or multiple arguments are given. */ + if (argc != 2 || strcmp(argv[1], "--help") == 0) { + fprintf(stderr, "Usage: %s [pathname]\n", argv[0]); + return 1; + } + + /* Exit if file stat cannot be obtained. */ + if (lstat(argv[1], &sb) == -1) { + perror(argv[0]); + return 1; + } + + /* Exit if name of the owner cannot be retrieved. */ + if (!getpwuid(sb.st_uid)) { + return 1; + } + + /* Print the user name of file owner. */ + pw = getpwuid(sb.st_uid); + printf("%s\n", pw->pw_name); + return 0; +} diff --git a/bin/kiss-readlink.c b/bin/kiss-readlink.c deleted file mode 100644 index cc6c8ff..0000000 --- a/bin/kiss-readlink.c +++ /dev/null @@ -1,47 +0,0 @@ -/* kiss-readlink --- a utility replacement for readlink - * See LICENSE for copyright information. - * - * This is basically a 'readlink -f' command. - */ -#include -#include -#include -#include -#include - -#define DIR_MAX PATH_MAX - NAME_MAX - 1 - - -char *realpath(const char *path, char *resolved_path); - -int -main(int argc, char *argv[]) -{ - - char buf[PATH_MAX]; - - /* We are going to use these if the file doesn't exist, but we can still - * use directories above the file. We are using dname and bname so that - * they don't clash with the functions with the same name. - */ - char dname[DIR_MAX]; /* directory name */ - char bname[NAME_MAX]; /* base name */ - sprintf(bname, "%s", (basename(argv[1]))); - - if (argc != 2 || strcmp(argv[1], "--help") == 0) { - fprintf(stderr, "usage: %s [file]\n", argv[0]); - return 1; - } - - if (!realpath(argv[1], buf)) { - - if (!realpath(dirname(argv[1]), dname)) { - perror(argv[0]); - return 1; - } - sprintf(buf, "%s/%s", dname, bname); - } - - printf("%s\n", buf); - return 0; -} diff --git a/bin/kiss-stat.c b/bin/kiss-stat.c deleted file mode 100644 index 4380503..0000000 --- a/bin/kiss-stat.c +++ /dev/null @@ -1,41 +0,0 @@ -/* kiss-stat --- a utility for getting the user name of file owner - * See LICENSE for copyright information - * - * The reason this simple tool exists is because 'stat' is not - * portable and ls is not exactly stable enough for scripting. - * This program is for outputting the owner name, and that's it. - */ - -#include -#include -#include -#include - -struct passwd *pw; -struct stat sb; - -int -main (int argc, char *argv[]) -{ - /* Exit if no or multiple arguments are given. */ - if (argc != 2 || strcmp(argv[1], "--help") == 0) { - fprintf(stderr, "Usage: %s [pathname]\n", argv[0]); - return 1; - } - - /* Exit if file stat cannot be obtained. */ - if (lstat(argv[1], &sb) == -1) { - perror(argv[0]); - return 1; - } - - /* Exit if name of the owner cannot be retrieved. */ - if (!getpwuid(sb.st_uid)) { - return 1; - } - - /* Print the user name of file owner. */ - pw = getpwuid(sb.st_uid); - printf("%s\n", pw->pw_name); - return 0; -} -- cgit v1.2.3