d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * This file and its contents are supplied under the terms of the
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * Common Development and Distribution License ("CDDL"), version 1.0.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * You may only use this file in accordance with the terms of version
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * 1.0 of the CDDL.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * A full copy of the text of the CDDL should have accompanied this
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * source. A copy of the CDDL is also available via the Internet at
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * Copyright (c) 2012 by Delphix. All rights reserved.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * Make a directory busy. If the argument is an existing file or directory,
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * simply open it directly and pause. If not, verify that the parent directory
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * exists, and create a new file in that directory.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy (void) fprintf(stderr, "Usage: %s <dirname|filename>\n", progname);
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy } else if (pid != 0) {
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy while ((c = getopt(argc, argv, "fr")) != -1) {
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy /* Open the file or directory read only */
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy /* Run in the foreground */
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * The argument supplied doesn't exist. Copy the path, and
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * remove the trailing slash if presnt.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * Get the directory and file names, using the current directory
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * if the provided path doesn't specify a directory at all.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy if ((slash = strrchr(arg, '/')) == NULL) {
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy /* The directory portion of the path must exist */
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy if ((ret = stat(dname, &sbuf)) != 0 || !(sbuf.st_mode &
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy if ((fpath = (char *)malloc(dlen + 1 + flen + 1)) == NULL)
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy (void) memset(fpath, '\0', dlen + 1 + flen + 1);
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy } else if ((sbuf.st_mode & S_IFMT) == S_IFREG ||
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy } else if ((sbuf.st_mode & S_IFMT) == S_IFDIR) {
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy flags = rflag == B_FALSE ? O_CREAT | O_RDWR : O_RDONLY;
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy /* NOTREACHED */