aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/file.c
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2023-04-29 22:14:41 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2023-04-29 22:16:42 +0200
commitb58e8bfe04f4f8bcbb18dd6cb7c01f4d44b1f9ec (patch)
tree4c7afa46057e73d111e3ef9004a95205f66b0179 /src/file.c
parentdedupe command line routines (diff)
downloadcimple-b58e8bfe04f4f8bcbb18dd6cb7c01f4d44b1f9ec.tar.gz
cimple-b58e8bfe04f4f8bcbb18dd6cb7c01f4d44b1f9ec.zip
cmd_line: read executable name from /proc/self/exe
Diffstat (limited to 'src/file.c')
-rw-r--r--src/file.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/file.c b/src/file.c
index 55e1691..bc7af8e 100644
--- a/src/file.c
+++ b/src/file.c
@@ -63,6 +63,40 @@ free_old:
return ret;
}
+char *my_readlink(const char *path)
+{
+ size_t current_size = 256;
+ char *buf = NULL;
+
+ while (1) {
+ buf = realloc(buf, current_size);
+ if (!buf) {
+ log_errno("realloc");
+ goto free;
+ }
+
+ ssize_t res = readlink(path, buf, current_size);
+ if (res < 0) {
+ log_errno("readlink");
+ goto free;
+ }
+
+ if ((size_t)res == current_size) {
+ current_size *= 2;
+ continue;
+ }
+
+ break;
+ }
+
+ return buf;
+
+free:
+ free(buf);
+
+ return NULL;
+}
+
int file_exists(const char *path)
{
struct stat stat;