Skip to content

Commit d6e76cc

Browse files
tfarinatorvalds
authored andcommitted
uemacs: input.c: Fix mkstemp warning.
Fix the following warning: input.c: In function ‘getstring’: input.c:590: warning: ignoring return value of ‘mkstemp’, declared with attribute warn_unused_result This add usage.c module for die function. This also add wrapper.c module for the xmkstemp that is wrapper function around the original mkstemp function. Both module codes was largelly based on git, linux and sparse codes. Signed-off-by: Thiago Farina <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent f286294 commit d6e76cc

File tree

6 files changed

+61
-9
lines changed

6 files changed

+61
-9
lines changed

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ PROGRAM=em
1919
SRC=ansi.c basic.c bind.c buffer.c crypt.c display.c eval.c exec.c \
2020
file.c fileio.c ibmpc.c input.c isearch.c line.c lock.c main.c \
2121
pklock.c posix.c random.c region.c search.c spawn.c tcap.c \
22-
termio.c vmsvt.c vt52.c window.c word.c names.c globals.c version.c
22+
termio.c vmsvt.c vt52.c window.c word.c names.c globals.c version.c \
23+
usage.c wrapper.c
2324

2425
OBJ=ansi.o basic.o bind.o buffer.o crypt.o display.o eval.o exec.o \
2526
file.o fileio.o ibmpc.o input.o isearch.o line.o lock.o main.o \
2627
pklock.o posix.o random.o region.o search.o spawn.o tcap.o \
27-
termio.o vmsvt.o vt52.o window.o word.o names.o globals.o version.o
28+
termio.o vmsvt.o vt52.o window.o word.o names.o globals.o version.o \
29+
usage.o wrapper.o
2830

2931
HDR=ebind.h edef.h efunc.h epath.h estruct.h evar.h util.h version.h
3032

input.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
/* INPUT.C
1+
/* input.c
22
*
33
* Various input routines
44
*
55
* written by Daniel Lawrence 5/9/86
66
* modified by Petri Kutvonen
77
*/
88

9-
#include <stdio.h>
10-
#include <unistd.h>
11-
#include "estruct.h"
12-
#include "edef.h"
13-
#include "efunc.h"
9+
#include <stdio.h>
10+
#include <unistd.h>
11+
12+
#include "estruct.h"
13+
#include "edef.h"
14+
#include "efunc.h"
15+
#include "wrapper.h"
1416

1517
#if PKCODE
1618
#if MSDOS && TURBO
@@ -587,7 +589,7 @@ int getstring(char *prompt, char *buf, int nbuf, int eolchar)
587589
if (!iswild)
588590
strcat(ffbuf, "*");
589591
strcat(ffbuf, " >");
590-
mkstemp(tmp);
592+
xmkstemp(tmp);
591593
strcat(ffbuf, tmp);
592594
strcat(ffbuf, " 2>&1");
593595
system(ffbuf);

usage.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "usage.h"
2+
3+
#include <stdarg.h>
4+
#include <stdio.h>
5+
#include <stdlib.h>
6+
7+
static void report(const char* prefix, const char *err, va_list params)
8+
{
9+
char msg[4096];
10+
vsnprintf(msg, sizeof(msg), err, params);
11+
fprintf(stderr, "%s%s\n", prefix, msg);
12+
}
13+
14+
void die(const char* err, ...)
15+
{
16+
va_list params;
17+
18+
va_start(params, err);
19+
report("fatal: ", err, params);
20+
va_end(params);
21+
exit(128);
22+
}

usage.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef USAGE_H_
2+
#define USAGE_H_
3+
4+
extern void die(const char* err, ...);
5+
6+
#endif /* USAGE_H_ */

wrapper.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "usage.h"
2+
3+
#include <stdlib.h>
4+
5+
/* Function copyright: git */
6+
int xmkstemp(char *template)
7+
{
8+
int fd;
9+
10+
fd = mkstemp(template);
11+
if (fd < 0)
12+
die("Unable to create temporary file");
13+
return fd;
14+
}

wrapper.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef WRAPPER_H_
2+
#define WRAPPER_H_
3+
4+
extern int xmkstemp(char *template);
5+
6+
#endif /* WRAPPER_H_ */

0 commit comments

Comments
 (0)