sync code with last improvements from OpenBSD
This commit is contained in:
parent
e1ec829e63
commit
68fa196282
30 changed files with 268 additions and 1060 deletions
|
@ -72,7 +72,7 @@ XpmReadFileToBuffer(
|
|||
*buffer_return = NULL;
|
||||
|
||||
#ifndef VAX11C
|
||||
fd = open(filename, O_RDONLY);
|
||||
fd = open(filename, O_RDONLY | O_CLOEXEC);
|
||||
#else
|
||||
fd = open(filename, O_RDONLY, NULL);
|
||||
#endif
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
LFUNC(OpenReadFile, int, (const char *filename, xpmData *mdata));
|
||||
LFUNC(xpmDataClose, void, (xpmData *mdata));
|
||||
|
||||
FUNC(xpmPipeThrough, FILE*, (int fd,
|
||||
HFUNC(xpmPipeThrough, FILE*, (int fd,
|
||||
const char *cmd,
|
||||
const char *arg1,
|
||||
const char *mode));
|
||||
|
@ -212,7 +212,7 @@ OpenReadFile(
|
|||
mdata->stream.file = (stdin);
|
||||
mdata->type = XPMFILE;
|
||||
} else {
|
||||
int fd = open(filename, O_RDONLY);
|
||||
int fd = open(filename, O_RDONLY | O_CLOEXEC);
|
||||
#if defined(NO_ZPIPE)
|
||||
if ( fd < 0 )
|
||||
return XpmOpenFailed;
|
||||
|
@ -229,11 +229,11 @@ OpenReadFile(
|
|||
return (XpmNoMemory);
|
||||
strcpy(compressfile, filename);
|
||||
strcpy(compressfile + len, ext = ".Z");
|
||||
fd = open(compressfile, O_RDONLY);
|
||||
fd = open(compressfile, O_RDONLY | O_CLOEXEC);
|
||||
if ( fd < 0 )
|
||||
{
|
||||
strcpy(compressfile + len, ext = ".gz");
|
||||
fd = open(compressfile, O_RDONLY);
|
||||
fd = open(compressfile, O_RDONLY | O_CLOEXEC);
|
||||
if ( fd < 0 )
|
||||
{
|
||||
XpmFree(compressfile);
|
||||
|
|
|
@ -45,7 +45,7 @@ XpmWriteFileFromBuffer(
|
|||
char *buffer)
|
||||
{
|
||||
size_t fcheck, len;
|
||||
FILE *fp = fopen(filename, "w");
|
||||
FILE *fp = fopen(filename, "w" FOPEN_CLOEXEC);
|
||||
|
||||
if (!fp)
|
||||
return XpmOpenFailed;
|
||||
|
|
|
@ -315,7 +315,7 @@ WriteExtensions(
|
|||
|
||||
|
||||
#ifndef NO_ZPIPE
|
||||
FUNC(xpmPipeThrough, FILE*, (int fd,
|
||||
HFUNC(xpmPipeThrough, FILE*, (int fd,
|
||||
const char* cmd,
|
||||
const char* arg1,
|
||||
const char* mode));
|
||||
|
@ -336,7 +336,7 @@ OpenWriteFile(
|
|||
#ifndef NO_ZPIPE
|
||||
size_t len;
|
||||
#endif
|
||||
int fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0644);
|
||||
int fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0644);
|
||||
if ( fd < 0 )
|
||||
return(XpmOpenFailed);
|
||||
#ifndef NO_ZPIPE
|
||||
|
|
|
@ -103,6 +103,13 @@ extern FILE *popen();
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef O_CLOEXEC
|
||||
# define FOPEN_CLOEXEC "e"
|
||||
#else
|
||||
# define FOPEN_CLOEXEC ""
|
||||
# define O_CLOEXEC 0
|
||||
#endif
|
||||
|
||||
#define XPMMAXCMTLEN BUFSIZ
|
||||
typedef struct {
|
||||
unsigned int type;
|
||||
|
@ -144,7 +151,7 @@ typedef struct {
|
|||
const char *Eoa; /* string ending assignment */
|
||||
} xpmDataType;
|
||||
|
||||
extern xpmDataType xpmDataTypes[];
|
||||
extern _X_HIDDEN xpmDataType xpmDataTypes[];
|
||||
|
||||
/*
|
||||
* rgb values and ascii names (from rgb text file) rgb values,
|
||||
|
@ -158,7 +165,7 @@ typedef struct {
|
|||
/* Maximum number of rgb mnemonics allowed in rgb text file. */
|
||||
#define MAX_RGBNAMES 1024
|
||||
|
||||
extern const char *xpmColorKeys[];
|
||||
extern _X_HIDDEN const char *xpmColorKeys[];
|
||||
|
||||
#define TRANSPARENT_COLOR "None" /* this must be a string! */
|
||||
|
||||
|
@ -167,31 +174,31 @@ extern const char *xpmColorKeys[];
|
|||
|
||||
/* XPM internal routines */
|
||||
|
||||
FUNC(xpmParseData, int, (xpmData *data, XpmImage *image, XpmInfo *info));
|
||||
FUNC(xpmParseDataAndCreate, int, (Display *display, xpmData *data,
|
||||
HFUNC(xpmParseData, int, (xpmData *data, XpmImage *image, XpmInfo *info));
|
||||
HFUNC(xpmParseDataAndCreate, int, (Display *display, xpmData *data,
|
||||
XImage **image_return,
|
||||
XImage **shapeimage_return,
|
||||
XpmImage *image, XpmInfo *info,
|
||||
XpmAttributes *attributes));
|
||||
|
||||
FUNC(xpmFreeColorTable, void, (XpmColor *colorTable, int ncolors));
|
||||
HFUNC(xpmFreeColorTable, void, (XpmColor *colorTable, int ncolors));
|
||||
|
||||
FUNC(xpmInitAttributes, void, (XpmAttributes *attributes));
|
||||
HFUNC(xpmInitAttributes, void, (XpmAttributes *attributes));
|
||||
|
||||
FUNC(xpmInitXpmImage, void, (XpmImage *image));
|
||||
HFUNC(xpmInitXpmImage, void, (XpmImage *image));
|
||||
|
||||
FUNC(xpmInitXpmInfo, void, (XpmInfo *info));
|
||||
HFUNC(xpmInitXpmInfo, void, (XpmInfo *info));
|
||||
|
||||
FUNC(xpmSetInfoMask, void, (XpmInfo *info, XpmAttributes *attributes));
|
||||
FUNC(xpmSetInfo, void, (XpmInfo *info, XpmAttributes *attributes));
|
||||
FUNC(xpmSetAttributes, void, (XpmAttributes *attributes, XpmImage *image,
|
||||
HFUNC(xpmSetInfoMask, void, (XpmInfo *info, XpmAttributes *attributes));
|
||||
HFUNC(xpmSetInfo, void, (XpmInfo *info, XpmAttributes *attributes));
|
||||
HFUNC(xpmSetAttributes, void, (XpmAttributes *attributes, XpmImage *image,
|
||||
XpmInfo *info));
|
||||
|
||||
#if !defined(FOR_MSW) && !defined(AMIGA)
|
||||
FUNC(xpmCreatePixmapFromImage, int, (Display *display, Drawable d,
|
||||
HFUNC(xpmCreatePixmapFromImage, int, (Display *display, Drawable d,
|
||||
XImage *ximage, Pixmap *pixmap_return));
|
||||
|
||||
FUNC(xpmCreateImageFromPixmap, void, (Display *display, Pixmap pixmap,
|
||||
HFUNC(xpmCreateImageFromPixmap, void, (Display *display, Pixmap pixmap,
|
||||
XImage **ximage_return,
|
||||
unsigned int *width,
|
||||
unsigned int *height));
|
||||
|
@ -211,10 +218,10 @@ typedef struct {
|
|||
xpmHashAtom *atomTable;
|
||||
} xpmHashTable;
|
||||
|
||||
FUNC(xpmHashTableInit, int, (xpmHashTable *table));
|
||||
FUNC(xpmHashTableFree, void, (xpmHashTable *table));
|
||||
FUNC(xpmHashSlot, xpmHashAtom *, (xpmHashTable *table, char *s));
|
||||
FUNC(xpmHashIntern, int, (xpmHashTable *table, char *tag, void *data));
|
||||
HFUNC(xpmHashTableInit, int, (xpmHashTable *table));
|
||||
HFUNC(xpmHashTableFree, void, (xpmHashTable *table));
|
||||
HFUNC(xpmHashSlot, xpmHashAtom *, (xpmHashTable *table, char *s));
|
||||
HFUNC(xpmHashIntern, int, (xpmHashTable *table, char *tag, void *data));
|
||||
|
||||
#if defined(_MSC_VER) && defined(_M_X64)
|
||||
#define HashAtomData(i) ((void *)(long long)i)
|
||||
|
@ -227,45 +234,45 @@ FUNC(xpmHashIntern, int, (xpmHashTable *table, char *tag, void *data));
|
|||
|
||||
/* I/O utility */
|
||||
|
||||
FUNC(xpmNextString, int, (xpmData *mdata));
|
||||
FUNC(xpmNextUI, int, (xpmData *mdata, unsigned int *ui_return));
|
||||
FUNC(xpmGetString, int, (xpmData *mdata, char **sptr, unsigned int *l));
|
||||
HFUNC(xpmNextString, int, (xpmData *mdata));
|
||||
HFUNC(xpmNextUI, int, (xpmData *mdata, unsigned int *ui_return));
|
||||
HFUNC(xpmGetString, int, (xpmData *mdata, char **sptr, unsigned int *l));
|
||||
|
||||
#define xpmGetC(mdata) \
|
||||
((!mdata->type || mdata->type == XPMBUFFER) ? \
|
||||
(*mdata->cptr++) : (getc(mdata->stream.file)))
|
||||
|
||||
FUNC(xpmNextWord, unsigned int,
|
||||
HFUNC(xpmNextWord, unsigned int,
|
||||
(xpmData *mdata, char *buf, unsigned int buflen));
|
||||
FUNC(xpmGetCmt, int, (xpmData *mdata, char **cmt));
|
||||
FUNC(xpmParseHeader, int, (xpmData *mdata));
|
||||
FUNC(xpmParseValues, int, (xpmData *data, unsigned int *width,
|
||||
HFUNC(xpmGetCmt, int, (xpmData *mdata, char **cmt));
|
||||
HFUNC(xpmParseHeader, int, (xpmData *mdata));
|
||||
HFUNC(xpmParseValues, int, (xpmData *data, unsigned int *width,
|
||||
unsigned int *height, unsigned int *ncolors,
|
||||
unsigned int *cpp, unsigned int *x_hotspot,
|
||||
unsigned int *y_hotspot, unsigned int *hotspot,
|
||||
unsigned int *extensions));
|
||||
|
||||
FUNC(xpmParseColors, int, (xpmData *data, unsigned int ncolors,
|
||||
HFUNC(xpmParseColors, int, (xpmData *data, unsigned int ncolors,
|
||||
unsigned int cpp, XpmColor **colorTablePtr,
|
||||
xpmHashTable *hashtable));
|
||||
|
||||
FUNC(xpmParseExtensions, int, (xpmData *data, XpmExtension **extensions,
|
||||
HFUNC(xpmParseExtensions, int, (xpmData *data, XpmExtension **extensions,
|
||||
unsigned int *nextensions));
|
||||
|
||||
/* RGB utility */
|
||||
|
||||
FUNC(xpmReadRgbNames, int, (const char *rgb_fname, xpmRgbName *rgbn));
|
||||
FUNC(xpmGetRgbName, char *, (xpmRgbName *rgbn, int rgbn_max,
|
||||
HFUNC(xpmReadRgbNames, int, (const char *rgb_fname, xpmRgbName *rgbn));
|
||||
HFUNC(xpmGetRgbName, char *, (xpmRgbName *rgbn, int rgbn_max,
|
||||
int red, int green, int blue));
|
||||
FUNC(xpmFreeRgbNames, void, (xpmRgbName *rgbn, int rgbn_max));
|
||||
HFUNC(xpmFreeRgbNames, void, (xpmRgbName *rgbn, int rgbn_max));
|
||||
#ifdef FOR_MSW
|
||||
FUNC(xpmGetRGBfromName,int, (char *name, int *r, int *g, int *b));
|
||||
HFUNC(xpmGetRGBfromName,int, (char *name, int *r, int *g, int *b));
|
||||
#endif
|
||||
|
||||
#ifndef AMIGA
|
||||
FUNC(xpm_xynormalizeimagebits, void, (register unsigned char *bp,
|
||||
HFUNC(xpm_xynormalizeimagebits, void, (register unsigned char *bp,
|
||||
register XImage *img));
|
||||
FUNC(xpm_znormalizeimagebits, void, (register unsigned char *bp,
|
||||
HFUNC(xpm_znormalizeimagebits, void, (register unsigned char *bp,
|
||||
register XImage *img));
|
||||
|
||||
/*
|
||||
|
@ -313,7 +320,7 @@ FUNC(xpm_znormalizeimagebits, void, (register unsigned char *bp,
|
|||
#endif /* not AMIGA */
|
||||
|
||||
#ifdef NEED_STRDUP
|
||||
FUNC(xpmstrdup, char *, (char *s1));
|
||||
HFUNC(xpmstrdup, char *, (char *s1));
|
||||
#else
|
||||
#undef xpmstrdup
|
||||
#define xpmstrdup strdup
|
||||
|
@ -321,14 +328,14 @@ FUNC(xpmstrdup, char *, (char *s1));
|
|||
#endif
|
||||
|
||||
#ifdef NEED_STRCASECMP
|
||||
FUNC(xpmstrcasecmp, int, (char *s1, char *s2));
|
||||
HFUNC(xpmstrcasecmp, int, (char *s1, char *s2));
|
||||
#else
|
||||
#undef xpmstrcasecmp
|
||||
#define xpmstrcasecmp strcasecmp
|
||||
#include <strings.h>
|
||||
#endif
|
||||
|
||||
FUNC(xpmatoui, unsigned int,
|
||||
HFUNC(xpmatoui, unsigned int,
|
||||
(char *p, unsigned int l, unsigned int *ui_return));
|
||||
|
||||
#endif
|
||||
|
|
|
@ -66,7 +66,7 @@ xpmReadRgbNames(
|
|||
xpmRgbName *rgb;
|
||||
|
||||
/* Open the rgb text file. Abort if error. */
|
||||
if ((rgbf = fopen(rgb_fname, "r")) == NULL)
|
||||
if ((rgbf = fopen(rgb_fname, "r" FOPEN_CLOEXEC)) == NULL)
|
||||
return 0;
|
||||
|
||||
/* Loop reading each line in the file. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue