3 * Copyright (C) 2019 Simone Piccardi
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /****************************************************************
21 * Program test_linkat.c:
22 * Program to test use of linkat with an O_TMPFILE or linking another file
23 * using AT_EMPTY_PATH or AT_SYMLINK_FOLLOW on /proc/self/fd/N
24 * giving the option to wait to remove source file
26 * Author: Simone Piccardi
29 * Usage: testlinkat -h give all info's
31 ****************************************************************/
33 * Include needed headers
36 #include <errno.h> /* error definitions and routines */
37 #include <stdlib.h> /* C standard library */
38 #include <unistd.h> /* unix standard library */
39 #include <stdio.h> /* standard I/O library */
40 #include <string.h> /* C strings library */
42 #include <libgen.h> /* needed for dirname e basename */
44 #include <sys/types.h>
50 /* Help printing routine */
53 int main(int argc, char *argv[])
56 * Variables definition
59 * Input section: decode command line parameters
63 opterr = 0; /* don't want writing to stderr */
64 while ( (i = getopt(argc, argv, "hw:f:")) != -1) {
69 case 'h': /* help option */
70 printf("Wrong -h option use\n");
74 case '?': /* unrecognized options */
75 printf("Unrecognized options -%c\n",optopt);
77 default: /* should not reached */
81 /* ***********************************************************
83 * Options processing completed
87 * ***********************************************************/
88 /* There must be 1 remaing parameters */
89 if ( (argc-optind) != 2 ) {
90 printf("From %d arguments, removed %d options\n", argc, optind);
93 char *path, *dir, *file;
94 path = strdup(argv[optind]);
95 file = basename(argv[optind]);
96 dir = dirname(argv[optind]);
97 printf("Destination on dir %s file: %s\n with path: %s\n",
99 int newfd, res, count;
100 count = strlen(argv[optind+1]);
101 newfd = open(dir, O_PATH|O_RDWR);
103 perror("Cannot open destination dir");
106 res = InitFile(newfd, file, argv[optind+1], count);
111 * routine to print usage info and exit
114 printf("Program test_initfile : create a file with initial content \n");
116 printf(" test_initfile [-h] pathname 'test to be written on pathname' \n");
117 printf(" -h print this help\n");