futil.c revision 327
1327Sjkh#ifndef lint 2327Sjkhstatic const char *rcsid = "$Id: futil.c,v 1.3 1993/08/26 08:12:25 jkh Exp $"; 3327Sjkh#endif 4327Sjkh 5327Sjkh/* 6327Sjkh * FreeBSD install - a package for the installation and maintainance 7327Sjkh * of non-core utilities. 8327Sjkh * 9327Sjkh * Redistribution and use in source and binary forms, with or without 10327Sjkh * modification, are permitted provided that the following conditions 11327Sjkh * are met: 12327Sjkh * 1. Redistributions of source code must retain the above copyright 13327Sjkh * notice, this list of conditions and the following disclaimer. 14327Sjkh * 2. Redistributions in binary form must reproduce the above copyright 15327Sjkh * notice, this list of conditions and the following disclaimer in the 16327Sjkh * documentation and/or other materials provided with the distribution. 17327Sjkh * 18327Sjkh * Jordan K. Hubbard 19327Sjkh * 18 July 1993 20327Sjkh * 21327Sjkh * Miscellaneous file access utilities. 22327Sjkh * 23327Sjkh */ 24327Sjkh 25327Sjkh#include "lib.h" 26327Sjkh#include "add.h" 27327Sjkh 28327Sjkh/* 29327Sjkh * Assuming dir is a desired directory name, make it and all intervening 30327Sjkh * directories necessary. 31327Sjkh */ 32327Sjkh 33327Sjkhint 34327Sjkhmake_hierarchy(char *dir) 35327Sjkh{ 36327Sjkh char *cp1, *cp2; 37327Sjkh 38327Sjkh if (dir[0] == '/') 39327Sjkh cp1 = cp2 = dir + 1; 40327Sjkh else 41327Sjkh cp1 = cp2 = dir; 42327Sjkh while (cp2) { 43327Sjkh if ((cp2 = index(cp1, '/')) !=NULL ) 44327Sjkh *cp2 = '\0'; 45327Sjkh if (fexists(dir)) { 46327Sjkh if (!isdir(dir)) 47327Sjkh return FAIL; 48327Sjkh } 49327Sjkh else { 50327Sjkh if (vsystem("mkdir %s", dir)) 51327Sjkh return FAIL; 52327Sjkh apply_perms(NULL, dir); 53327Sjkh } 54327Sjkh /* Put it back */ 55327Sjkh if (cp2) { 56327Sjkh *cp2 = '/'; 57327Sjkh cp1 = cp2 + 1; 58327Sjkh } 59327Sjkh } 60327Sjkh return SUCCESS; 61327Sjkh} 62327Sjkh 63327Sjkh/* Using permission defaults, apply them as necessary */ 64327Sjkhvoid 65327Sjkhapply_perms(char *dir, char *file) 66327Sjkh{ 67327Sjkh char fname[FILENAME_MAX]; 68327Sjkh 69327Sjkh if (!dir || *file == '/') /* absolute path? */ 70327Sjkh strcpy(fname, file); 71327Sjkh else 72327Sjkh sprintf(fname, "%s/%s", dir, file); 73327Sjkh if (Mode) 74327Sjkh if (vsystem("chmod -R %s %s", Mode, fname)) 75327Sjkh whinge("Couldn't change mode of '%s' to '%s'.", 76327Sjkh fname, Mode); 77327Sjkh if (Owner) 78327Sjkh if (vsystem("chown -R %s %s", Owner, fname)) 79327Sjkh whinge("Couldn't change owner of '%s' to '%s'.", 80327Sjkh fname, Owner); 81327Sjkh if (Group) 82327Sjkh if (vsystem("chgrp -R %s %s", Group, fname)) 83327Sjkh whinge("Couldn't change group of '%s' to '%s'.", 84327Sjkh fname, Group); 85327Sjkh} 86327Sjkh 87