X-Git-Url: https://git.saurik.com/apple/system_cmds.git/blobdiff_plain/6d658acdb5f61932718109ed8f339604b778ab80..aaff5f0175051936f3b5ec9815c2df5d726dc5b6:/mkfile.tproj/mkfile.c diff --git a/mkfile.tproj/mkfile.c b/mkfile.tproj/mkfile.c index 5f70877..19eadb9 100644 --- a/mkfile.tproj/mkfile.c +++ b/mkfile.tproj/mkfile.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ @@ -42,6 +41,7 @@ #include #include #include +#include #define BF_SZ 512 /* Size of write chunks */ @@ -57,11 +57,12 @@ main (argc, argv) char *b_num, *prog_name; char *options = "nv"; char c; - quad_t multiplier = 1; - quad_t file_size; + off_t multiplier = 1; + off_t file_size; int len; int empty = 0; int verbose = 0; + char* endptr = NULL; prog_name = argv[0]; /* Get program name */ if (1 == argc) @@ -118,8 +119,10 @@ main (argc, argv) if (*argv == NULL) /* Was a file name given? */ usage(prog_name, options); - if ((file_size = strtoq(b_num, NULL, 10)) == 0 ) + if ((file_size = strtoll(b_num, &endptr, 10)) == 0 && + (*endptr != 0 && endptr != &b_num[len])) { err(1, "Bad file size!"); + } while ( *argv != NULL ) { /* Create file for each file_name */ create_file(*argv, file_size*multiplier, empty, verbose); @@ -143,9 +146,12 @@ create_file(file_name, size, empty, verbose) char buff[BF_SZ]; int fd, bytes_written = BF_SZ; quad_t i; - mode_t mode; + mode_t mode = S_IRUSR | S_IWUSR; + + /* If superuser, then set sticky bit */ + if (!geteuid()) mode |= S_ISVTX; - if ((fd = open(file_name, O_RDWR | O_CREAT | O_TRUNC )) == -1) + if ((fd = open(file_name, O_RDWR | O_CREAT | O_TRUNC, mode)) == -1) err(1, NULL); @@ -177,17 +183,11 @@ create_file(file_name, size, empty, verbose) } } + if (fchmod(fd, mode)) /* Change permissions */ + err_rm(file_name, NULL); - mode = S_IRUSR | S_IWUSR; - /* If superuser, then set sticky bit */ - if (! geteuid()) - mode |= S_ISVTX; - - if (fchmod(fd, mode)) /* Change permissions */ - err_rm(file_name, NULL); - - if ((close(fd)) == -1) - err_rm(file_name, NULL); + if ((close(fd)) == -1) + err_rm(file_name, NULL); if (verbose) (void)fprintf(stderr, "%s %qd bytes\n", file_name, size);