summaryrefslogtreecommitdiffstats
path: root/gnu/libexec/uucp/libunix/addbas.c
blob: 8597918a3c953469cfc437cae10466e7c49e00f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* addbas.c
   If we have a directory, add in a base name.  */

#include "uucp.h"

#include "uudefs.h"
#include "sysdep.h"
#include "system.h"

/* If we have a directory, add a base name.  */

char *
zsysdep_add_base (zfile, zname)
     const char *zfile;
     const char *zname;
{
  size_t clen;
  const char *zlook;
  char *zfree;
  char *zret;

#if DEBUG > 0
  if (*zfile != '/')
    ulog (LOG_FATAL, "zsysdep_add_base: %s: Can't happen", zfile);
#endif

  clen = strlen (zfile);

  if (zfile[clen - 1] != '/')
    {
      if (! fsysdep_directory (zfile))
	return zbufcpy (zfile);
      zfree = NULL;
    }
  else
    {
      /* Trim out the trailing '/'.  */
      zfree = zbufcpy (zfile);
      zfree[clen - 1] = '\0';
      zfile = zfree;
    }

  zlook = strrchr (zname, '/');
  if (zlook != NULL)
    zname = zlook + 1;

  zret = zsysdep_in_dir (zfile, zname);
  ubuffree (zfree);
  return zret;
}
OpenPOWER on IntegriCloud