aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--toys/basename.c31
-rw-r--r--toys/dirname.c26
-rw-r--r--toys/mkfifo.c46
-rw-r--r--toys/touch.c108
-rw-r--r--toys/tty.c29
5 files changed, 0 insertions, 240 deletions
diff --git a/toys/basename.c b/toys/basename.c
deleted file mode 100644
index 70ffe5ba..00000000
--- a/toys/basename.c
+++ /dev/null
@@ -1,31 +0,0 @@
-/* vi: set sw=4 ts=4:
- *
- * basename.c - print non-directory portion of path
- *
- * Copyright 2007 Charlie Shepherd <masterdriverz@gentoo.org>
- *
- * See http://www.opengroup.org/onlinepubs/009695399/utilities/basename.html
-
-USE_BASENAME(NEWTOY(basename, "<1>2", TOYFLAG_BIN))
-
-config BASENAME
- bool "basename"
- default y
- help
- usage: basename path [suffix]
-
- Print the part of path after the last slash, optionally minus suffix.
-*/
-
-#include "toys.h"
-
-void basename_main(void)
-{
- char *name = basename(*toys.optargs);
- char *suffix = toys.optargs[1];
- if (suffix) {
- char *end = name+strlen(name)-strlen(suffix);
- if (end>name && !strcmp(end,suffix)) *end=0;
- }
- puts(name);
-}
diff --git a/toys/dirname.c b/toys/dirname.c
deleted file mode 100644
index 759cee7f..00000000
--- a/toys/dirname.c
+++ /dev/null
@@ -1,26 +0,0 @@
-/* vi: set sw=4 ts=4:
- *
- * dirname.c - print directory portion of path, or "." if none.
- *
- * Copyright 2007 Charlie Shepherd <masterdriverz@gentoo.org>
- *
- * See http://www.opengroup.org/onlinepubs/009695399/utilities/dirname.html
-
-USE_DIRNAME(NEWTOY(dirname, "<1>1", TOYFLAG_BIN))
-
-config DIRNAME
- bool "dirname"
- default y
- help
- usage: dirname path
-
- Print the part of path up to the last slash.
-*/
-
-#include "toys.h"
-#include <libgen.h>
-
-void dirname_main(void)
-{
- puts(dirname(*toys.optargs));
-}
diff --git a/toys/mkfifo.c b/toys/mkfifo.c
deleted file mode 100644
index 39ec51ad..00000000
--- a/toys/mkfifo.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/* vi: set sw=4 ts=4:
- *
- * mkfifo.c: Create a named pipe.
- *
- * See http://www.opengroup.org/onlinepubs/009695399/utilities/mkfifo.html
-
-USE_MKFIFO(NEWTOY(mkfifo, "<1m:", TOYFLAG_BIN|TOYFLAG_UMASK))
-
-config MKFIFO
- bool "mkfifo"
- default y
- help
- usage: mkfifo [-m mode] name...
-
- Makes a named pipe at name.
-
- -m mode The mode of the pipe(s) created by mkfifo. It defaults
- to 0644. This number is in octal, optionally preceded
- by a leading zero.
-*/
-
-#include "toys.h"
-
-DEFINE_GLOBALS(
- char *mode;
-)
-
-#define TT this.mkfifo
-
-void mkfifo_main(void)
-{
- char *arg;
- int i;
- mode_t mode;
-
- if (toys.optflags) {
- char *end;
- mode = (mode_t)strtol(TT.mode, &end, 8);
- if (end<=TT.mode || *end || mode<0 || mode>0777)
- error_exit("Invalid mode");
- } else mode = 0644;
-
- for (i = 0; (arg = toys.optargs[i]); i++)
- if (mkfifo(arg, mode))
- perror_exit(arg);
-}
diff --git a/toys/touch.c b/toys/touch.c
deleted file mode 100644
index bead28fb..00000000
--- a/toys/touch.c
+++ /dev/null
@@ -1,108 +0,0 @@
-/* vi: set sw=4 ts=4:
- *
- * touch.c - Modify a file's timestamps.
- *
- * Copyright (C) 2007 Charlie Shepherd <masterdriverz@gentoo.org>
- *
- * See http://www.opengroup.org/onlinepubs/009695399/utilities/touch.html
-
-USE_TOUCH(NEWTOY(touch, "l#t:r:mca", TOYFLAG_BIN|TOYFLAG_UMASK))
-
-config TOUCH
- bool "touch"
- default y
- help
- usage: touch [-acm] [-r FILE] [-t MMDDhhmm] [-l bytes] FILE...
-
- Change file timestamps, ensure file existance and change file length.
-
- -a Only change the access time.
- -c Do not create the file if it doesn't exist.
- -l Length to truncate (or sparsely extend) file to.
- -m Only change the modification time.
- -r Reference file to take timestamps from.
- -t Time to change {a,m}time to.
-*/
-
-#include "toys.h"
-
-DEFINE_GLOBALS(
- char *ref_file;
- char *time;
- long length;
-)
-
-#define TT this.touch
-
-#define OPT_MTIME 0x01
-#define OPT_NOCREATE 0x02
-#define OPT_ATIME 0x04
-#define OPT_REFERENCE 0x08
-#define OPT_TIME 0x10
-#define OPT_LENGTH 0x20
-
-void touch_main(void)
-{
- char *arg;
- int i, set_a, set_m;
- time_t curr_a, curr_m;
-
- set_a = !!(toys.optflags & OPT_ATIME);
- set_m = !!(toys.optflags & OPT_MTIME);
-
- // Use timestamp on a file
- if (toys.optflags & OPT_REFERENCE) {
- struct stat sb;
-
- if (toys.optflags & OPT_TIME)
- error_exit("Redundant time source");
- xstat(TT.ref_file, &sb);
- curr_m = sb.st_mtime;
- curr_a = sb.st_atime;
-
- // Use time specified on command line.
- } else if (toys.optflags & OPT_TIME) {
- struct tm t;
- time_t curr;
- char *c;
-
- curr = time(NULL);
- if (localtime_r(&curr, &t)
- || !(c = strptime(TT.time, "%m%d%H%M", &t))
- || *c || -1==(curr_a = curr_m = mktime(&t)))
- {
- error_exit("Unknown time %s", TT.time);
- }
-
- // use current time
- } else curr_m = curr_a = time(NULL);
-
- for (i = 0; (arg = toys.optargs[i]); i++) {
- struct utimbuf buf;
- struct stat sb;
-
- buf.modtime = curr_m;
- buf.actime = curr_a;
-
- if (stat(arg, &sb)) {
- if (!(toys.optflags & OPT_NOCREATE)) {
- xcreate(arg, O_CREAT, 0644);
- if (stat(arg, &sb))
- goto error;
- }
- }
-
- if ((set_a+set_m) == 1) {
- /* We've been asked to only change one */
- if (set_a) buf.modtime = sb.st_mtime;
- else if (set_m) buf.actime = sb.st_atime;
- }
-
- if (toys.optflags & OPT_LENGTH)
- if (truncate(arg, TT.length))
- goto error;
- if (utime(arg, &buf))
-error:
- perror_exit(arg);
- }
-}
diff --git a/toys/tty.c b/toys/tty.c
deleted file mode 100644
index 6bc9cd34..00000000
--- a/toys/tty.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/* vi: set sw=4 ts=4:
- * tty.c - print terminal name of stdin
- *
- * Copyright 2007 Charlie Shepherd <masterdriverz@gentoo.org>
- *
- * See http://www.opengroup.org/onlinepubs/009695399/utilities/tty.html
-
-USE_TTY(NEWTOY(tty, "s", TOYFLAG_BIN))
-
-config TTY
- bool "tty"
- default y
- help
- Print the filename of the terminal connected to standard input.
-
- -s Don't print anything, only return an exit status.
-*/
-
-#include "toys.h"
-
-void tty_main(void)
-{
- char *name = ttyname(0);
- if (!toys.optflags) {
- if (name) puts(name);
- else puts("Not a tty");
- }
- toys.exitval = !name;
-}