test-get-currentexe.c
Go to the documentation of this file.
1 /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to
5  * deal in the Software without restriction, including without limitation the
6  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7  * sell copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19  * IN THE SOFTWARE.
20  */
21 
22 #include "uv.h"
23 #include "task.h"
24 #include <string.h>
25 
26 #ifndef _WIN32
27 #include <unistd.h>
28 #endif
29 
30 #define PATHMAX 4096
31 extern char executable_path[];
32 
33 TEST_IMPL(get_currentexe) {
34  char buffer[PATHMAX];
35  char path[PATHMAX];
36  size_t size;
37  char* match;
38  int r;
39 
40  size = sizeof(buffer) / sizeof(buffer[0]);
41  r = uv_exepath(buffer, &size);
42  ASSERT(!r);
43 
44 #ifdef _WIN32
45  snprintf(path, sizeof(path), "%s", executable_path);
46 #else
47  ASSERT(NULL != realpath(executable_path, path));
48 #endif
49 
50  match = strstr(buffer, path);
51  /* Verify that the path returned from uv_exepath is a subdirectory of
52  * executable_path.
53  */
54  ASSERT(match && !strcmp(match, path));
55  ASSERT(size == strlen(buffer));
56 
57  /* Negative tests */
58  size = sizeof(buffer) / sizeof(buffer[0]);
59  r = uv_exepath(NULL, &size);
60  ASSERT(r == UV_EINVAL);
61 
62  r = uv_exepath(buffer, NULL);
63  ASSERT(r == UV_EINVAL);
64 
65  size = 0;
66  r = uv_exepath(buffer, &size);
67  ASSERT(r == UV_EINVAL);
68 
69  memset(buffer, -1, sizeof(buffer));
70 
71  size = 1;
72  r = uv_exepath(buffer, &size);
73  ASSERT(r == 0);
74  ASSERT(size == 0);
75  ASSERT(buffer[0] == '\0');
76 
77  memset(buffer, -1, sizeof(buffer));
78 
79  size = 2;
80  r = uv_exepath(buffer, &size);
81  ASSERT(r == 0);
82  ASSERT(size == 1);
83  ASSERT(buffer[0] != '\0');
84  ASSERT(buffer[1] == '\0');
85 
86  return 0;
87 }
task.h
memset
return memset(p, 0, total)
match
unsigned char match[65280+2]
Definition: bloaty/third_party/zlib/examples/gun.c:165
string.h
ASSERT
#define ASSERT(expr)
Definition: task.h:102
check_documentation.path
path
Definition: check_documentation.py:57
executable_path
char executable_path[]
Definition: runner.c:30
buffer
char buffer[1024]
Definition: libuv/docs/code/idle-compute/main.c:8
uv_exepath
UV_EXTERN int uv_exepath(char *buffer, size_t *size)
Definition: aix-common.c:79
uv.h
TEST_IMPL
TEST_IMPL(get_currentexe)
Definition: test-get-currentexe.c:33
fix_build_deps.r
r
Definition: fix_build_deps.py:491
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
PATHMAX
#define PATHMAX
Definition: test-get-currentexe.c:30


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:26