summaryrefslogtreecommitdiff
path: root/src/regress/lib/libc/basename
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2025-04-14 17:32:06 +0000
committercvs2svn <admin@example.com>2025-04-14 17:32:06 +0000
commiteb8dd9dca1228af0cd132f515509051ecfabf6f6 (patch)
treeedb6da6af7e865d488dc1a29309f1e1ec226e603 /src/regress/lib/libc/basename
parent247f0352e0ed72a4f476db9dc91f4d982bc83eb2 (diff)
downloadopenbsd-tb_20250414.tar.gz
openbsd-tb_20250414.tar.bz2
openbsd-tb_20250414.zip
This commit was manufactured by cvs2git to create tag 'tb_20250414'.tb_20250414
Diffstat (limited to 'src/regress/lib/libc/basename')
-rw-r--r--src/regress/lib/libc/basename/Makefile3
-rw-r--r--src/regress/lib/libc/basename/basename_test.c77
2 files changed, 0 insertions, 80 deletions
diff --git a/src/regress/lib/libc/basename/Makefile b/src/regress/lib/libc/basename/Makefile
deleted file mode 100644
index 958b06fd11..0000000000
--- a/src/regress/lib/libc/basename/Makefile
+++ /dev/null
@@ -1,3 +0,0 @@
1PROG=basename_test
2
3.include <bsd.regress.mk>
diff --git a/src/regress/lib/libc/basename/basename_test.c b/src/regress/lib/libc/basename/basename_test.c
deleted file mode 100644
index 7272c46b1d..0000000000
--- a/src/regress/lib/libc/basename/basename_test.c
+++ /dev/null
@@ -1,77 +0,0 @@
1/*
2 * Copyright (c) 2007 Bret S. Lambert <blambert@gsipt.net>
3 *
4 * Public domain.
5 */
6
7#include <libgen.h>
8#include <stdio.h>
9#include <string.h>
10#include <limits.h>
11#include <errno.h>
12
13int
14main(void)
15{
16 char path[2 * PATH_MAX];
17 const char *dir = "junk/";
18 const char *fname = "file.name.ext";
19 char *str;
20 int i;
21
22 /* Test normal functioning */
23 strlcpy(path, "/", sizeof(path));
24 strlcat(path, dir, sizeof(path));
25 strlcat(path, fname, sizeof(path));
26 str = basename(path);
27 if (strcmp(str, fname) != 0)
28 goto fail;
29
30 /*
31 * There are four states that require special handling:
32 *
33 * 1) path is NULL
34 * 2) path is the empty string
35 * 3) path is composed entirely of slashes
36 * 4) the resulting name is larger than PATH_MAX
37 *
38 * The first two cases require that a pointer
39 * to the string "." be returned.
40 *
41 * The third case requires that a pointer
42 * to the string "/" be returned.
43 *
44 * The final case requires that NULL be returned
45 * and errno * be set to ENAMETOOLONG.
46 */
47 /* Case 1 */
48 str = basename(NULL);
49 if (strcmp(str, ".") != 0)
50 goto fail;
51
52 /* Case 2 */
53 strlcpy(path, "", sizeof(path));
54 str = basename(path);
55 if (strcmp(str, ".") != 0)
56 goto fail;
57
58 /* Case 3 */
59 for (i = 0; i < PATH_MAX - 1; i++)
60 strlcat(path, "/", sizeof(path)); /* path cleared above */
61 str = basename(path);
62 if (strcmp(str, "/") != 0)
63 goto fail;
64
65 /* Case 4 */
66 strlcpy(path, "/", sizeof(path));
67 strlcat(path, dir, sizeof(path));
68 for (i = 0; i <= PATH_MAX; i += sizeof(fname))
69 strlcat(path, fname, sizeof(path));
70 str = basename(path);
71 if (str != NULL || errno != ENAMETOOLONG)
72 goto fail;
73
74 return (0);
75fail:
76 return (1);
77}