Skip to content

Commit 85924e6

Browse files
committed
kfc.c: cleanup
1 parent ea1ab62 commit 85924e6

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

kfc.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#define _POSIX_C_SOURCE 200809L
12
#include <dirent.h>
23
#include <getopt.h>
34
#include <stdio.h>
@@ -8,7 +9,6 @@
89
#include <unistd.h>
910
#include "kfc.h"
1011

11-
1212
int
1313
find_palettes(void)
1414
{
@@ -88,7 +88,7 @@ list_palette(void)
8888

8989
if (p.dr == NULL)
9090
{
91-
printf("Could not open directory");
91+
fprintf(stderr, "Could not open directory\n");
9292
return 1;
9393
}
9494

@@ -109,7 +109,7 @@ random_palette(void)
109109
p.randf = 0;
110110
if (p.dr == NULL)
111111
{
112-
printf("Could not open directory");
112+
fprintf(stderr, "Could not open directory\n");
113113
return 1;
114114
}
115115

@@ -174,12 +174,12 @@ main(int argc, char **argv)
174174
exit(2);
175175
}
176176
strcat(p.CONF, "/kfc");
177-
sprintf(p.CCUR, "%s/current", p.CONF);
178-
sprintf(p.CSEQ, "%s/sequence", p.CONF);
177+
snprintf(p.CCUR, sizeof(p.CCUR), "%s/current", p.CONF);
178+
snprintf(p.CSEQ, sizeof(p.CSEQ), "%s/sequence", p.CONF);
179179

180180
if ( mkdir(p.CONF,0777) == 0 )
181181
{
182-
printf("Created 'kfc' directory in XDG_CONFIG_HOME.");
182+
puts("Created 'kfc' directory in XDG_CONFIG_HOME.");
183183
}
184184

185185
if (find_palettes() == 1)
@@ -193,12 +193,12 @@ main(int argc, char **argv)
193193
switch (p.cval)
194194
{
195195
case 'r':
196-
sprintf(p.SEL, "%s/%s", p.SEQ, p.MODE);
196+
snprintf(p.SEL, sizeof(p.SEL), "%s/%s", p.SEQ, p.MODE);
197197
random_palette();
198198
select_palette();
199199
break;
200200
case 'l':
201-
sprintf(p.SEL, "%s/%s", p.SEQ, p.MODE);
201+
snprintf(p.SEL, sizeof(p.SEL), "%s/%s", p.SEQ, p.MODE);
202202
list_palette();
203203
break;
204204
case 'L':
@@ -211,7 +211,7 @@ main(int argc, char **argv)
211211
p.errf++;
212212
break;
213213
case 's':
214-
sprintf(p.SEL, "%s/%s/%s", p.SEQ, p.MODE, optarg);
214+
snprintf(p.SEL, sizeof(p.SEL), "%s/%s/%s", p.SEQ, p.MODE, optarg);
215215
select_palette();
216216
break;
217217
case 'p':

kfc.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ struct
1010
size_t len;
1111
char *MODE; // "light" or "dark"
1212
char *CONF; // configuration path
13+
char SEQ[225];
1314
char CCUR[255]; // configuration path, current file
1415
char CSEQ[255]; // configuration path, sequence file
15-
char SEL[1024]; // selected palette
16-
char SEQ[1024];
17-
char PRI[1024];
18-
char CLI[1024];
16+
char SEL[1025]; // selected palette
17+
char PRI[1025];
18+
char CLI[1025];
1919
} p;

0 commit comments

Comments
 (0)