Back to index

nagios-plugins  1.4.16
Defines | Functions
dirname.h File Reference
#include <stdbool.h>
#include <stddef.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define DIRECTORY_SEPARATOR   '/'
#define ISSLASH(C)   ((C) == DIRECTORY_SEPARATOR)
#define FILE_SYSTEM_PREFIX_LEN(Filename)   0
#define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE   0
#define DOUBLE_SLASH_IS_DISTINCT_ROOT   0
#define IS_ABSOLUTE_FILE_NAME(F)   (ISSLASH ((F)[0]) || 0 < FILE_SYSTEM_PREFIX_LEN (F))
#define IS_RELATIVE_FILE_NAME(F)   (! IS_ABSOLUTE_FILE_NAME (F))

Functions

char * mdir_name (char const *file)
size_t base_len (char const *file)
size_t dir_len (char const *file)
char * last_component (char const *file)
bool strip_trailing_slashes (char *file)

Define Documentation

#define DIRECTORY_SEPARATOR   '/'

Definition at line 26 of file dirname.h.

Definition at line 51 of file dirname.h.

Definition at line 47 of file dirname.h.

#define FILE_SYSTEM_PREFIX_LEN (   Filename)    0

Definition at line 42 of file dirname.h.

#define IS_ABSOLUTE_FILE_NAME (   F)    (ISSLASH ((F)[0]) || 0 < FILE_SYSTEM_PREFIX_LEN (F))

Definition at line 57 of file dirname.h.

#define IS_RELATIVE_FILE_NAME (   F)    (! IS_ABSOLUTE_FILE_NAME (F))

Definition at line 60 of file dirname.h.

#define ISSLASH (   C)    ((C) == DIRECTORY_SEPARATOR)

Definition at line 30 of file dirname.h.


Function Documentation

size_t base_len ( char const file)

Definition at line 58 of file basename-lgpl.c.

{
  size_t len;
  size_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name);

  for (len = strlen (name);  1 < len && ISSLASH (name[len - 1]);  len--)
    continue;

  if (DOUBLE_SLASH_IS_DISTINCT_ROOT && len == 1
      && ISSLASH (name[0]) && ISSLASH (name[1]) && ! name[2])
    return 2;

  if (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE && prefix_len
      && len == prefix_len && ISSLASH (name[prefix_len]))
    return prefix_len + 1;

  return len;
}

Here is the caller graph for this function:

size_t dir_len ( char const file)

Definition at line 32 of file dirname-lgpl.c.

{
  size_t prefix_length = FILE_SYSTEM_PREFIX_LEN (file);
  size_t length;

  /* Advance prefix_length beyond important leading slashes.  */
  prefix_length += (prefix_length != 0
                    ? (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
                       && ISSLASH (file[prefix_length]))
                    : (ISSLASH (file[0])
                       ? ((DOUBLE_SLASH_IS_DISTINCT_ROOT
                           && ISSLASH (file[1]) && ! ISSLASH (file[2])
                           ? 2 : 1))
                       : 0));

  /* Strip the basename and any redundant slashes before it.  */
  for (length = last_component (file) - file;
       prefix_length < length; length--)
    if (! ISSLASH (file[length - 1]))
      break;
  return length;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* last_component ( char const file)

Definition at line 30 of file basename-lgpl.c.

{
  char const *base = name + FILE_SYSTEM_PREFIX_LEN (name);
  char const *p;
  bool saw_slash = false;

  while (ISSLASH (*base))
    base++;

  for (p = base; *p; p++)
    {
      if (ISSLASH (*p))
        saw_slash = true;
      else if (saw_slash)
        {
          base = p;
          saw_slash = false;
        }
    }

  return (char *) base;
}

Here is the caller graph for this function:

char* mdir_name ( char const file)

Definition at line 71 of file dirname-lgpl.c.

{
  size_t length = dir_len (file);
  bool append_dot = (length == 0
                     || (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
                         && length == FILE_SYSTEM_PREFIX_LEN (file)
                         && file[2] != '\0' && ! ISSLASH (file[2])));
  char *dir = malloc (length + append_dot + 1);
  if (!dir)
    return NULL;
  memcpy (dir, file, length);
  if (append_dot)
    dir[length++] = '.';
  dir[length] = '\0';
  return dir;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool strip_trailing_slashes ( char *  file)

Definition at line 31 of file stripslash.c.

{
  char *base = last_component (file);
  char *base_lim;
  bool had_slash;

  /* last_component returns "" for file system roots, but we need to turn
     `///' into `/'.  */
  if (! *base)
    base = file;
  base_lim = base + base_len (base);
  had_slash = (*base_lim != '\0');
  *base_lim = '\0';
  return had_slash;
}

Here is the call graph for this function: