2
* Copyright (C) 2002-2007 Novell/SUSE
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation, version 2 of the
16
#include <sys/types.h>
22
struct option long_options[] = {
23
{"delete", 0, 0, 'd'}, /* delete the directory after opening */
24
{"rename", 1, 0, 'r'}, /* rename the directory to -- */
28
static void usage (char * program)
30
fprintf(stderr, "usage: %s [--delete] dir file\n", program);
31
fprintf(stderr, "%s\n", "$Id$");
35
int main(int argc, char *argv[])
37
int fd = -1, dirfd = -1;
41
char *dir, *file, *newdir = NULL;
43
while ((c = getopt_long (argc, argv, "+hdr:", long_options, NULL)) != -1) {
60
if (argc - optind != 2)
64
file = argv[optind + 1];
66
dirfd = open(dir, O_RDONLY | O_DIRECTORY);
68
fprintf(stderr, "FAIL: open %s failed - %s\n",
69
dir, strerror(errno));
73
if (do_delete && rmdir(dir) == -1) {
74
fprintf(stderr, "FAIL: rmdir %s failed - %s\n",
75
dir, strerror(errno));
77
} else if (do_rename && rename(dir, newdir) == -1) {
78
fprintf(stderr, "FAIL: rename %s, %s failed - %s\n",
79
dir, newdir, strerror(errno));
83
fd = openat(dirfd, file, O_RDWR | O_CREAT, S_IWUSR | S_IRUSR);
85
fprintf(stderr, "FAIL: openat %s failed - %s\n",
86
file, strerror(errno));