Back to index

nagios-plugins  1.4.16
Functions
dirname-lgpl.c File Reference
#include <config.h>
#include "dirname.h"
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Functions

size_t dir_len (char const *file)
char * mdir_name (char const *file)

Function Documentation

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* 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: