File: 0007-Replace-set_progname-that-allocates-with-err-3.patch

package info (click to toggle)
ttyrec 1.1.7.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 856 kB
  • sloc: ansic: 2,490; sh: 246; makefile: 49; perl: 48
file content (111 lines) | stat: -rw-r--r-- 2,598 bytes parent folder | download | duplicates (2)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
From: =?utf-8?b?0L3QsNCx?= <nabijaczleweli@nabijaczleweli.xyz>
Date: Sat, 25 Jan 2025 17:23:19 +0100
Subject: Replace set_progname() that allocates with err(3)

---
 io.c      | 20 +++++---------------
 io.h      |  1 -
 ttyplay.c |  1 -
 ttytime.c |  1 -
 4 files changed, 5 insertions(+), 18 deletions(-)

diff --git a/io.c b/io.c
index 0d4f3fe..63321a5 100644
--- a/io.c
+++ b/io.c
@@ -45,6 +45,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <endian.h>
+#include <err.h>
 
 #include "io.h"
 #include "ttyrec.h"
@@ -86,21 +87,13 @@ int write_header(FILE *fp, Header *h)
 }
 
 
-static char *progname = "";
-void set_progname(const char *name)
-{
-    progname = strdup(name);
-}
-
-
 FILE *efopen(const char *path, const char *mode)
 {
     FILE *fp = fopen(path, mode);
 
     if (fp == NULL)
     {
-        fprintf(stderr, "%s: %s: %s\n", progname, path, strerror(errno));
-        exit(EXIT_FAILURE);
+        err(EXIT_FAILURE, "%s\n", path);
     }
     return fp;
 }
@@ -112,8 +105,7 @@ int edup(int oldfd)
 
     if (fd == -1)
     {
-        fprintf(stderr, "%s: dup failed: %s\n", progname, strerror(errno));
-        exit(EXIT_FAILURE);
+        err(EXIT_FAILURE, "dup failed\n");
     }
     return fd;
 }
@@ -125,8 +117,7 @@ int edup2(int oldfd, int newfd)
 
     if (fd == -1)
     {
-        fprintf(stderr, "%s: dup2 failed: %s\n", progname, strerror(errno));
-        exit(EXIT_FAILURE);
+        err(EXIT_FAILURE, "dup2 failed\n");
     }
     return fd;
 }
@@ -138,8 +129,7 @@ FILE *efdopen(int fd, const char *mode)
 
     if (fp == NULL)
     {
-        fprintf(stderr, "%s: fdopen failed: %s\n", progname, strerror(errno));
-        exit(EXIT_FAILURE);
+        err(EXIT_FAILURE, "fdopen failed\n");
     }
     return fp;
 }
diff --git a/io.h b/io.h
index c8b5418..d96a049 100644
--- a/io.h
+++ b/io.h
@@ -9,6 +9,5 @@ FILE *efopen(const char *path, const char *mode);
 int edup(int oldfd);
 int edup2(int oldfd, int newfd);
 FILE *efdopen(int fd, const char *mode);
-void set_progname(const char *name);
 
 #endif
diff --git a/ttyplay.c b/ttyplay.c
index 6b519fe..c496872 100644
--- a/ttyplay.c
+++ b/ttyplay.c
@@ -350,7 +350,6 @@ int main(int argc, char **argv)
     FILE           *input = NULL;
     struct termios old, new;
 
-    set_progname(argv[0]);
     while (1)
     {
 #ifdef HAVE_zstd
diff --git a/ttytime.c b/ttytime.c
index 7f74be1..a1e54d5 100644
--- a/ttytime.c
+++ b/ttytime.c
@@ -73,7 +73,6 @@ int main(int argc, char **argv)
 {
     int i;
 
-    set_progname(argv[0]);
     for (i = 1; i < argc; i++)
     {
         char *filename = argv[i];