Back to index

tetex-bin  3.0
Functions
xdirname.c File Reference
#include <kpathsea/config.h>
#include <kpathsea/c-pathch.h>

Go to the source code of this file.

Functions

string xdirname P1C (const_string, name)

Function Documentation

string xdirname P1C ( const_string  ,
name   
)

Definition at line 29 of file xdirname.c.

{
  string ret;
  unsigned limit = 0, loc;

  /* Ignore a NULL name. */
  if (!name)
      return NULL;
  
  if (NAME_BEGINS_WITH_DEVICE(name)) {
      limit = 2;
#if defined(WIN32) || defined(__CYGWIN__)
  } else if (IS_UNC_NAME(name)) {
      for (limit = 2; name[limit] && !IS_DIR_SEP(name[limit]); limit++)
          ;
      if (name[limit]) {
          for (limit++ ; name[limit] && !IS_DIR_SEP(name[limit]); limit++)
              ;
          limit--;
      } else {
          /* malformed UNC name, backup */
          limit = 2;
      }
#endif
  }

  for (loc = strlen (name); loc > limit && !IS_DIR_SEP (name[loc-1]); loc--)
      ;

  if (loc == limit && limit > 0) {
      if (limit == 2) {
          ret = (string)xmalloc(limit + 2);
          ret[0] = name[0];
          ret[1] = name[1];
          ret[2] = '.';
          ret[3] = '\0';
      } else {
          ret = (string)xmalloc(limit + 2);
          strcpy(ret, name);
      }
  } else {
      /* If have ///a, must return /, so don't strip off everything.  */
      while (loc > limit+1 && IS_DIR_SEP (name[loc-1])) {
          loc--;
      }
      ret = (string)xmalloc(loc+1);
      strncpy(ret, name, loc);
      ret[loc] = '\0';
  }
    
  return ret;
}

Here is the call graph for this function: