src/lib/scan.c
void split_path_and_filename(const char *fname, POOLMEM **path, int *pnl,
        POOLMEM **file, int *fnl)
{
   const char *f;
   int slen;
   int len = slen = strlen(fname);

   /*
    * Find path without the filename.
    * I.e. everything after the last / is a "filename".
    * OK, maybe it is a directory name, but we treat it like
    * a filename. If we don't find a / then the whole name
    * must be a path name (e.g. c:).
    */
   f = fname + len - 1;
   /* "strip" any trailing slashes */
   while (slen > 1 && IsPathSeparator(*f)) {
      slen--;
      f--;
   }
   /* Walk back to last slash -- begin of filename */
   while (slen > 0 && !IsPathSeparator(*f)) {
      slen--;
      f--;
   }
   if (IsPathSeparator(*f)) {         /* did we find a slash? */
      f++;                            /* yes, point to filename */
   } else {                           /* no, whole thing must be path name */
      f = fname;
   }
   Dmsg2(200, "after strip len=%d f=%s\n", len, f);
   *fnl = fname - f + len;
   if (*fnl > 0) {
      *file = check_pool_memory_size(*file, *fnl+1);
      memcpy(*file, f, *fnl);    /* copy filename */
   }
   (*file)[*fnl] = 0;

   *pnl = f - fname;
   if (*pnl > 0) {
      *path = check_pool_memory_size(*path, *pnl+1);
      memcpy(*path, fname, *pnl);
   }
   (*path)[*pnl] = 0;

   Dmsg2(200, "pnl=%d fnl=%d\n", *pnl, *fnl);
   Dmsg3(200, "split fname=%s path=%s file=%s\n", fname, *path, *file);
}
/*
 * Given a full filename, split it into its path
 *  and filename parts. They are returned in pool memory
 *  in the arguments provided.
 */
Given a full filename, split it into its path
and filename parts. They are returned in pool memory
in the arguments provided.
Given a full filename split it into its path and filename parts . They are returned in pool memory in the arguments provided .
void split_path_and_filename(const char *fname, POOLMEM **path, int *pnl,
        POOLMEM **file, int *fnl)
{
   const char *f;
   int slen;
   int len = slen = strlen(fname);
   f = fname + len - 1;
   while (slen > 1 && IsPathSeparator(*f)) {
      slen--;
      f--;
   }
   while (slen > 0 && !IsPathSeparator(*f)) {
      slen--;
      f--;
   }
   if (IsPathSeparator(*f)) {         
      f++;                            
   } else {                           
      f = fname;
   }
   Dmsg2(200, "after strip len=%d f=%s\n", len, f);
   *fnl = fname - f + len;
   if (*fnl > 0) {
      *file = check_pool_memory_size(*file, *fnl+1);
      memcpy(*file, f, *fnl);    
   }
   (*file)[*fnl] = 0;
   *pnl = f - fname;
   if (*pnl > 0) {
      *path = check_pool_memory_size(*path, *pnl+1);
      memcpy(*path, fname, *pnl);
   }
   (*path)[*pnl] = 0;
   Dmsg2(200, "pnl=%d fnl=%d\n", *pnl, *fnl);
   Dmsg3(200, "split fname=%s path=%s file=%s\n", fname, *path, *file);
}
void split_path_and_filename ( const char * fname , POOLMEM * * path , int * pnl , POOLMEM * * file , int * fnl ) { const char * f ; int slen ; int len = slen = strlen ( fname ) ; f = fname + len - 1 ; while ( slen > 1 && IsPathSeparator ( * f ) ) { slen -- ; f -- ; } while ( slen > 0 && ! IsPathSeparator ( * f ) ) { slen -- ; f -- ; } if ( IsPathSeparator ( * f ) ) { f ++ ; } else { f = fname ; } Dmsg2 ( 200 , " \n " , len , f ) ; * fnl = fname - f + len ; if ( * fnl > 0 ) { * file = check_pool_memory_size ( * file , * fnl + 1 ) ; memcpy ( * file , f , * fnl ) ; } ( * file ) [ * fnl ] = 0 ; * pnl = f - fname ; if ( * pnl > 0 ) { * path = check_pool_memory_size ( * path , * pnl + 1 ) ; memcpy ( * path , fname , * pnl ) ; } ( * path ) [ * pnl ] = 0 ; Dmsg2 ( 200 , " \n " , * pnl , * fnl ) ; Dmsg3 ( 200 , " \n " , fname , * path , * file ) ; }
Given a full filename, split it into its path
  and filename parts.
Given a full filename split it into its path and filename parts .
/*
    * Find path without the filename.
    * I.e. everything after the last / is a "filename".
    * OK, maybe it is a directory name, but we treat it like
    * a filename. If we don't find a / then the whole name
    * must be a path name (e.g. c:).
    */ /* "strip" any trailing slashes */ /* Walk back to last slash -- begin of filename */ /* did we find a slash? */ /* yes, point to filename */ /* no, whole thing must be path name */ /* copy filename */