"Fossies" - the Fresh Open Source Software Archive

Member "coda-6.9.5/coda-src/asr/path.c" (26 Jun 2007, 2476 Bytes) of package /linux/misc/old/coda-6.9.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "path.c" see the Fossies "Dox" file reference documentation.

    1 /* BLURB gpl
    2 
    3                            Coda File System
    4                               Release 6
    5 
    6           Copyright (c) 1987-2003 Carnegie Mellon University
    7                   Additional copyrights listed below
    8 
    9 This  code  is  distributed "AS IS" without warranty of any kind under
   10 the terms of the GNU General Public Licence Version 2, as shown in the
   11 file  LICENSE.  The  technical and financial  contributors to Coda are
   12 listed in the file CREDITS.
   13 
   14                         Additional copyrights
   15                            none currently
   16 
   17 #*/
   18 
   19 #ifdef __cplusplus
   20 extern "C" {
   21 #endif
   22 
   23 #ifdef HAVE_CONFIG_H
   24 #include <config.h>
   25 #endif
   26 
   27 #include "asr.h"
   28 
   29 #include <unistd.h>
   30 #include <stdlib.h>
   31 #include <sys/param.h>
   32 #include "coda_string.h"
   33 #include <sys/types.h>
   34 #include <sys/stat.h>
   35 #include <sys/file.h>    
   36 #include <vcrcommon.h>
   37 
   38 #ifdef __cplusplus
   39 }
   40 #endif
   41 
   42 
   43 
   44 /* An implementation of path(3) which is a standard function in Mach OS
   45  * the behaviour is according to man page in Mach OS, which says,
   46  *
   47  *    The handling of most names is obvious, but several special
   48  *    cases exist.  The name "f", containing no slashes, is split
   49  *    into directory "." and filename "f".  The name "/" is direc-
   50  *    tory "/" and filename ".".  The path "" is directory "." and
   51  *    filename ".".
   52  *       -- manpage of path(3)
   53  */
   54 
   55 void path(char *pathname, char *direc, char *file)
   56 {
   57   char *maybebase, *tok;
   58   int num_char_to_be_rm;
   59 
   60   if (strlen(pathname)==0) {
   61     strcpy(direc, ".");
   62     strcpy(file, ".");
   63     return;
   64   }
   65   if (strchr(pathname, '/')==0) {
   66     strcpy(direc, ".");
   67     strcpy(file, pathname);
   68     return;
   69   } 
   70   if (strcmp(pathname, "/")==0) {
   71     strcpy(direc, "/");
   72     strcpy(file, ".");
   73     return;
   74   }
   75   strcpy(direc, pathname);
   76   maybebase = strtok(direc,"/");
   77   while ((tok = strtok(NULL,"/")))
   78     maybebase = tok;
   79   strcpy(file, maybebase);
   80   strcpy(direc, pathname);
   81   num_char_to_be_rm = strlen(file) + 
   82     (direc[strlen(pathname)-1]=='/' ? 1 : 0);/* any trailing slash ? */
   83   *(direc+strlen(pathname)-num_char_to_be_rm) = '\0';
   84     /* removing the component for file from direc */
   85   if (strlen(direc)==0) strcpy(direc,"."); /* this happen when pathname 
   86                                             * is "name/", for example */
   87   if (strlen(direc)>=2) /* don't do this if only '/' remains in direc */
   88     if (*(direc+strlen(direc)-1) == '/' )
   89       *(direc+strlen(direc)-1) = '\0'; 
   90        /* remove trailing slash in direc */
   91   return;
   92 }
   93 
   94 
   95