Mercurial > molko
changeset 420:7d2ebc334c8c
misc: rename core to util
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 12 Oct 2022 15:26:12 +0200 |
parents | 1b4e61bdb9ab |
children | 3edda1ce314c |
files | GNUmakefile src/libmlk-core/core/sys.c src/libmlk-core/core/sys_p.h src/libmlk-core/core/util.c src/libmlk-core/core/vfs-directory.c src/libmlk-core/core/zfile.c src/libmlk-port/port/basename.c src/libmlk-port/port/dirname.c src/libmlk-port/port/fmemopen.c src/libmlk-port/port/getopt.c src/libmlk-port/port/port.h src/libmlk-port/port/strlcat.c src/libmlk-port/port/strlcpy.c src/libmlk-rpg/rpg/map-file.c src/libmlk-rpg/rpg/save.c src/libmlk-rpg/rpg/tileset-file.c src/libmlk-util/util/fmemopen.c src/libmlk-util/util/openbsd/basename.c src/libmlk-util/util/openbsd/dirname.c src/libmlk-util/util/openbsd/getopt.c src/libmlk-util/util/openbsd/strlcat.c src/libmlk-util/util/openbsd/strlcpy.c src/libmlk-util/util/util.h src/tools/map/mlk-map.c |
diffstat | 24 files changed, 566 insertions(+), 566 deletions(-) [+] |
line wrap: on
line diff
--- a/GNUmakefile Wed Oct 12 15:06:18 2022 +0200 +++ b/GNUmakefile Wed Oct 12 15:26:12 2022 +0200 @@ -53,7 +53,7 @@ # Global INCS, OPTS and DEFS for every targets. INCS := -Iextern/libdt \ -Iextern/libsqlite \ - -Isrc/libmlk-port \ + -Isrc/libmlk-util \ -Isrc/libmlk-core \ -Isrc/libmlk-ui \ -Isrc/libmlk-rpg \ @@ -91,7 +91,7 @@ LIBMLK = $(LIBMLK_RPG) \ $(LIBMLK_UI) \ $(LIBMLK_CORE) \ - $(LIBMLK_PORT) \ + $(LIBMLK_UTIL) \ $(LIBMLK_SQLITE) \ $(MATH_LIBS) \ $(SDL2_LIBS) \ @@ -139,25 +139,25 @@ # }}} -# {{{ libmlk-port +# {{{ libmlk-util -LIBMLK_PORT := libmlk-port.a -LIBMLK_PORT_SRCS := src/libmlk-port/port/basename.c \ - src/libmlk-port/port/dirname.c \ - src/libmlk-port/port/fmemopen.c \ - src/libmlk-port/port/getopt.c \ - src/libmlk-port/port/strlcat.c \ - src/libmlk-port/port/strlcpy.c -LIBMLK_PORT_OBJS := $(LIBMLK_PORT_SRCS:.c=.o) -LIBMLK_PORT_DEPS := $(LIBMLK_PORT_SRCS:.c=.d) +LIBMLK_UTIL := libmlk-util.a +LIBMLK_UTIL_SRCS := src/libmlk-util/util/fmemopen.c \ + src/libmlk-util/util/openbsd/basename.c \ + src/libmlk-util/util/openbsd/dirname.c \ + src/libmlk-util/util/openbsd/getopt.c \ + src/libmlk-util/util/openbsd/strlcat.c \ + src/libmlk-util/util/openbsd/strlcpy.c +LIBMLK_UTIL_OBJS := $(LIBMLK_UTIL_SRCS:.c=.o) +LIBMLK_UTIL_DEPS := $(LIBMLK_UTIL_SRCS:.c=.d) --include $(LIBMLK_PORT_DEPS) +-include $(LIBMLK_UTIL_DEPS) -$(LIBMLK_PORT): INCS := -$(LIBMLK_PORT): OBJS := $(LIBMLK_PORT_OBJS) -$(LIBMLK_PORT): $(LIBMLK_PORT_OBJS) +$(LIBMLK_UTIL): INCS := +$(LIBMLK_UTIL): OBJS := $(LIBMLK_UTIL_OBJS) +$(LIBMLK_UTIL): $(LIBMLK_UTIL_OBJS) -all: $(LIBMLK_PORT) +all: $(LIBMLK_UTIL) # }}} @@ -186,9 +186,9 @@ MLK_MAP := src/tools/map/mlk-map -$(MLK_MAP): INCS := -Isrc/libmlk-port $(JANSSON_INCS) -$(MLK_MAP): LIBS := $(LIBMLK_PORT) $(JANSSON_LIBS) -$(MLK_MAP): $(LIBMLK_PORT) +$(MLK_MAP): INCS := -Isrc/libmlk-util $(JANSSON_INCS) +$(MLK_MAP): LIBS := $(LIBMLK_UTIL) $(JANSSON_LIBS) +$(MLK_MAP): $(LIBMLK_UTIL) all: $(MLK_MAP) @@ -419,7 +419,7 @@ $(EXAMPLES_EXE): private LIBS += $(LIBMLK) $(LIBMLK_EXAMPLE) $(EXAMPLES_EXE): private INCS += -Iexamples -$(EXAMPLES_EXE): $(LIBMLK_RPG) $(LIBMLK_UI) $(LIBMLK_CORE) $(LIBMLK_PORT) $(LIBMLK_SQLITE) $(LIBMLK_EXAMPLE) +$(EXAMPLES_EXE): $(LIBMLK_RPG) $(LIBMLK_UI) $(LIBMLK_CORE) $(LIBMLK_UTIL) $(LIBMLK_SQLITE) $(LIBMLK_EXAMPLE) examples: $(EXAMPLES_EXE) @@ -450,7 +450,7 @@ $(TESTS_EXE): private LIBS += $(LIBMLK) $(TESTS_EXE): private DEFS += -DDIRECTORY=\"$(CURDIR)/tests/assets\" -$(TESTS_EXE): $(LIBMLK_RPG) $(LIBMLK_UI) $(LIBMLK_CORE) $(LIBMLK_PORT) $(LIBMLK_SQLITE) +$(TESTS_EXE): $(LIBMLK_RPG) $(LIBMLK_UI) $(LIBMLK_CORE) $(LIBMLK_UTIL) $(LIBMLK_SQLITE) tests: $(TESTS_EXE) for t in $(TESTS_EXE); do ./$$t; done @@ -477,7 +477,7 @@ rm -f config.h rm -f $(MLK_BCC) $(MLK_MAP) $(MLK_TILESET) rm -f $(LIBMLK_SQLITE) $(LIBMLK_SQLITE_DEPS) $(LIBMLK_SQLITE_OBJS) - rm -f $(LIBMLK_PORT) $(LIBMLK_PORT_DEPS) $(LIBMLK_PORT_OBJS) + rm -f $(LIBMLK_UTIL) $(LIBMLK_UTIL_DEPS) $(LIBMLK_UTIL_OBJS) rm -f $(LIBMLK_CORE) $(LIBMLK_CORE_DEPS) $(LIBMLK_CORE_OBJS) rm -f $(LIBMLK_UI) $(LIBMLK_UI_DEPS) $(LIBMLK_UI_OBJS) $(LIBMLK_UI_DATA_OBJS) rm -f $(LIBMLK_RPG) $(LIBMLK_RPG_DEPS) $(LIBMLK_RPG_OBJS) $(LIBMLK_RPG_DATA_OBJS)
--- a/src/libmlk-core/core/sys.c Wed Oct 12 15:06:18 2022 +0200 +++ b/src/libmlk-core/core/sys.c Wed Oct 12 15:26:12 2022 +0200 @@ -40,7 +40,7 @@ #include <sndfile.h> -#include <port/port.h> +#include <util/util.h> #include "alloc.h" #include "error.h" @@ -80,10 +80,10 @@ char *pref; if ((pref = SDL_GetPrefPath(info.organization, info.name))) { - port_strlcpy(path, pref, sizeof (path)); + util_strlcpy(path, pref, sizeof (path)); SDL_free(pref); } else - port_strlcpy(path, "./", sizeof (path)); + util_strlcpy(path, "./", sizeof (path)); return path; } @@ -153,7 +153,7 @@ char path[PATH_MAX], *p; /* Copy the directory to normalize and iterate over '/'. */ - port_strlcpy(path, directory, sizeof (path)); + util_strlcpy(path, directory, sizeof (path)); normalize(path); #if defined(_WIN32)
--- a/src/libmlk-core/core/sys_p.h Wed Oct 12 15:06:18 2022 +0200 +++ b/src/libmlk-core/core/sys_p.h Wed Oct 12 15:26:12 2022 +0200 @@ -19,7 +19,7 @@ #ifndef MLK_CORE_SYS_P_H #define MLK_CORE_SYS_P_H -#include <port/port.h> +#include <util/util.h> #include <stddef.h>
--- a/src/libmlk-core/core/util.c Wed Oct 12 15:06:18 2022 +0200 +++ b/src/libmlk-core/core/util.c Wed Oct 12 15:26:12 2022 +0200 @@ -22,7 +22,7 @@ #include <SDL.h> -#include <port/port.h> +#include <util/util.h> #include "util.h"
--- a/src/libmlk-core/core/vfs-directory.c Wed Oct 12 15:06:18 2022 +0200 +++ b/src/libmlk-core/core/vfs-directory.c Wed Oct 12 15:26:12 2022 +0200 @@ -23,7 +23,7 @@ #include <stdlib.h> #include <string.h> -#include <port/port.h> +#include <util/util.h> #include "alloc.h" #include "error.h" @@ -104,7 +104,7 @@ struct self *self; self = alloc_new(sizeof (*self)); - port_strlcpy(self->base, path, sizeof (self->base)); + util_strlcpy(self->base, path, sizeof (self->base)); /* Remove terminator and switch to UNIX paths. */ normalize(self->base);
--- a/src/libmlk-core/core/zfile.c Wed Oct 12 15:06:18 2022 +0200 +++ b/src/libmlk-core/core/zfile.c Wed Oct 12 15:26:12 2022 +0200 @@ -47,7 +47,7 @@ # define O_BINARY 0 #endif -#include <port/port.h> +#include <util/util.h> #include "zfile.h" @@ -99,7 +99,7 @@ errno = EINVAL; goto fail; } - if (!(zf->fp = port_fmemopen(zf->data, datasz, "r"))) + if (!(zf->fp = util_fmemopen(zf->data, datasz, "r"))) goto fail; close(fd);
--- a/src/libmlk-port/port/basename.c Wed Oct 12 15:06:18 2022 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* $OpenBSD: basename.c,v 1.17 2020/10/20 19:30:14 naddy Exp $ */ - -/* - * Copyright (c) 1997, 2004 Todd C. Miller <millert@openbsd.org> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <errno.h> -#include <limits.h> -#include <string.h> - -#ifndef PATH_MAX -# define PATH_MAX 2048 -#endif - -char * -port_basename(char *path) -{ - static char bname[PATH_MAX]; - size_t len; - const char *endp, *startp; - - /* Empty or NULL string gets treated as "." */ - if (path == NULL || *path == '\0') { - bname[0] = '.'; - bname[1] = '\0'; - return (bname); - } - - /* Strip any trailing slashes */ - endp = path + strlen(path) - 1; - while (endp > path && *endp == '/') - endp--; - - /* All slashes becomes "/" */ - if (endp == path && *endp == '/') { - bname[0] = '/'; - bname[1] = '\0'; - return (bname); - } - - /* Find the start of the base */ - startp = endp; - while (startp > path && *(startp - 1) != '/') - startp--; - - len = endp - startp + 1; - if (len >= sizeof(bname)) { -#if defined(ENAMETOOLONG) - errno = ENAMETOOLONG; -#endif - return (NULL); - } - memcpy(bname, startp, len); - bname[len] = '\0'; - return (bname); -}
--- a/src/libmlk-port/port/dirname.c Wed Oct 12 15:06:18 2022 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -/* $OpenBSD: dirname.c,v 1.17 2020/10/20 19:30:14 naddy Exp $ */ - -/* - * Copyright (c) 1997, 2004 Todd C. Miller <millert@openbsd.org> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <errno.h> -#include <limits.h> -#include <string.h> - -#ifndef PATH_MAX -# define PATH_MAX 2048 -#endif - -char * -port_dirname(char *path) -{ - static char dname[PATH_MAX]; - size_t len; - const char *endp; - - /* Empty or NULL string gets treated as "." */ - if (path == NULL || *path == '\0') { - dname[0] = '.'; - dname[1] = '\0'; - return (dname); - } - - /* Strip any trailing slashes */ - endp = path + strlen(path) - 1; - while (endp > path && *endp == '/') - endp--; - - /* Find the start of the dir */ - while (endp > path && *endp != '/') - endp--; - - /* Either the dir is "/" or there are no slashes */ - if (endp == path) { - dname[0] = *endp == '/' ? '/' : '.'; - dname[1] = '\0'; - return (dname); - } else { - /* Move forward past the separating slashes */ - do { - endp--; - } while (endp > path && *endp == '/'); - } - - len = endp - path + 1; - if (len >= sizeof(dname)) { -#if defined(ENAMETOOLONG) - errno = ENAMETOOLONG; -#endif - return (NULL); - } - memcpy(dname, path, len); - dname[len] = '\0'; - return (dname); -}
--- a/src/libmlk-port/port/fmemopen.c Wed Oct 12 15:06:18 2022 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -/* - * fmemopen.h -- fmemopen polyfill - * - * Copyright (c) 2020-2022 David Demelier <markand@malikania.fr> - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "port.h" - -#if !defined(MLK_HAS_FMEMOPEN) - -#include <sys/stat.h> -#include <sys/types.h> -#include <fcntl.h> -#include <io.h> -#include <share.h> -#include <stdio.h> -#include <string.h> -#include <windows.h> - -FILE * -port_fmemopen(void *buf, size_t size, const char *mode) -{ - char temppath[MAX_PATH + 1], filename[MAX_PATH + 1]; - FILE *fp; - int fd, flags; - - flags = _O_CREAT | - _O_SHORT_LIVED | - _O_TEMPORARY | - _O_RDWR | - _O_NOINHERIT; - - if (strchr(mode, 'b')) - flags |= _O_BINARY; - - if (!GetTempPath(sizeof (temppath), temppath)) - return NULL; - if (!GetTempFileName(temppath, "MLK", 0, filename)) - return NULL; - if ((fd = _sopen(temppath, flags, _SH_DENYRW, _S_IREAD | _S_IWRITE)) < 0) - return NULL; - if (!(fp = _fdopen(fd, mode))) { - _close(fd); - return NULL; - } - - fwrite(buf, size, 1, fp); - rewind(fp); - - return fp; -} - -#else /* !MLK_HAS_FMEMOPEN */ - -#include <stdio.h> - -FILE * -port_fmemopen(void *buf, size_t len, const char *type) -{ - return fmemopen(buf, len, type); -} - -#endif
--- a/src/libmlk-port/port/getopt.c Wed Oct 12 15:06:18 2022 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,108 +0,0 @@ -/* - * Copyright (c) 1987, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -int port_opterr = 1, /* if error message should be printed */ - port_optind = 1, /* index into parent argv vector */ - port_optopt, /* character checked for validity */ - port_optreset; /* reset getopt */ -char *port_optarg; /* argument associated with option */ - -#define BADCH (int)'?' -#define BADARG (int)':' -#define EMSG "" - -/* - * getopt -- - * Parse argc/argv argument vector. - */ -int -port_getopt(int nargc, char * const *nargv, const char *ostr) -{ - static char *place = EMSG; /* option letter processing */ - char *oli; /* option letter list index */ - - if (ostr == NULL) - return (-1); - - if (port_optreset || !*place) { /* update scanning pointer */ - port_optreset = 0; - if (port_optind >= nargc || *(place = nargv[port_optind]) != '-') { - place = EMSG; - return (-1); - } - if (place[1] && *++place == '-') { /* found "--" */ - ++port_optind; - place = EMSG; - return (-1); - } - } /* option letter okay? */ - if ((port_optopt = (int)*place++) == (int)':' || - !(oli = strchr(ostr, port_optopt))) { - /* - * if the user didn't specify '-' as an option, - * assume it means -1. - */ - if (port_optopt == (int)'-') - return (-1); - if (!*place) - ++port_optind; - if (port_opterr && *ostr != ':') - (void)fprintf(stderr, - "illegal option -- %c\n", port_optopt); - return (BADCH); - } - if (*++oli != ':') { /* don't need argument */ - port_optarg = NULL; - if (!*place) - ++port_optind; - } - else { /* need an argument */ - if (*place) /* no white space */ - port_optarg = place; - else if (nargc <= ++port_optind) { /* no arg */ - place = EMSG; - if (*ostr == ':') - return (BADARG); - if (port_opterr) - (void)fprintf(stderr, - "option requires an argument -- %c\n", - port_optopt); - return (BADCH); - } - else /* white space */ - port_optarg = nargv[port_optind]; - place = EMSG; - ++port_optind; - } - return (port_optopt); /* dump back option letter */ -}
--- a/src/libmlk-port/port/port.h Wed Oct 12 15:06:18 2022 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,96 +0,0 @@ -/* - * port.h -- portability bits - * - * Copyright (c) 2020-2022 David Demelier <markand@malikania.fr> - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MLK_PORT_H -#define MLK_PORT_H - -#include <limits.h> -#include <stdio.h> - -/* - * This file helps finding what are the available features accross the various - * operating system in the landscape. - * - * The following macros are automatically set depending on the operating - * system: - * - * - MLK_OS_WINDOWS: running on any Windows machine - * - MLK_OS_POSIX: every mostly POSIX systems - * - * The following macro will be automatically defined unless the user override - * them: - * - * - MLK_HAS_FMEMOPEN: defined if fmemopen function is available. - * - MLK_HAS_SSIZE_T: defined if ssize_t typedef is available. - */ - -#if defined(_WIN32) -# define MLK_OS_WINDOWS -#elif defined(__FreeBSD__) -# define MLK_OS_POSIX -#elif defined(__OpenBSD__) -# define MLK_OS_POSIX -#elif defined(__NetBSD__) -# define MLK_OS_POSIX -#elif defined(__linux__) -# define MLK_OS_POSIX -#elif defined(__APPLE__) -# define MLK_OS_POSIX -# define MLK_OS_APPLE -#endif - -#if !defined(PATH_MAX) -# define PATH_MAX 2048 -#endif - -#if defined(MLK_OS_POSIX) && !defined(MLK_HAS_SSIZE_T) -# define MLK_HAS_SSIZE_T -#endif - -#if !defined(MLK_HAS_SSIZE_T) -typedef long long int ssize_t; -#endif - -#if defined(MLK_OS_POSIX) && !defined(MLK_HAS_FMEMOPEN) -# define MLK_HAS_FMEMOPEN -#endif - -size_t -port_strlcpy(char *, const char *, size_t); - -size_t -port_strlcat(char *, const char *, size_t); - -FILE * -port_fmemopen(void *, size_t, const char *); - -char * -port_basename(char *); - -char * -port_dirname(char *); - -extern int port_opterr; -extern int port_optind; -extern int port_optopt; -extern char *port_optarg; - -int -port_getopt(int, char **, const char *); - -#endif /* !MLK_PORT_H */
--- a/src/libmlk-port/port/strlcat.c Wed Oct 12 15:06:18 2022 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/* $OpenBSD: strlcat.c,v 1.19 2019/01/25 00:19:25 millert Exp $ */ - -/* - * Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <stddef.h> -#include <string.h> - -/* - * Appends src to string dst of size dsize (unlike strncat, dsize is the - * full size of dst, not space left). At most dsize-1 characters - * will be copied. Always NUL terminates (unless dsize <= strlen(dst)). - * Returns strlen(src) + MIN(dsize, strlen(initial dst)). - * If retval >= dsize, truncation occurred. - */ -size_t -port_strlcat(char *dst, const char *src, size_t dsize) -{ - const char *odst = dst; - const char *osrc = src; - size_t n = dsize; - size_t dlen; - - /* Find the end of dst and adjust bytes left but don't go past end. */ - while (n-- != 0 && *dst != '\0') - dst++; - dlen = dst - odst; - n = dsize - dlen; - - if (n-- == 0) - return(dlen + strlen(src)); - while (*src != '\0') { - if (n != 0) { - *dst++ = *src; - n--; - } - src++; - } - *dst = '\0'; - - return(dlen + (src - osrc)); /* count does not include NUL */ -}
--- a/src/libmlk-port/port/strlcpy.c Wed Oct 12 15:06:18 2022 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* $OpenBSD: strlcpy.c,v 1.16 2019/01/25 00:19:25 millert Exp $ */ - -/* - * Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <stddef.h> - -/* - * Copy string src to buffer dst of size dsize. At most dsize-1 - * chars will be copied. Always NUL terminates (unless dsize == 0). - * Returns strlen(src); if retval >= dsize, truncation occurred. - */ -size_t -port_strlcpy(char *dst, const char *src, size_t dsize) -{ - const char *osrc = src; - size_t nleft = dsize; - - /* Copy as many bytes as will fit. */ - if (nleft != 0) { - while (--nleft != 0) { - if ((*dst++ = *src++) == '\0') - break; - } - } - - /* Not enough room in dst, add NUL and traverse rest of src. */ - if (nleft == 0) { - if (dsize != 0) - *dst = '\0'; /* NUL-terminate dst */ - while (*src++) - ; - } - - return(src - osrc - 1); /* count does not include NUL */ -}
--- a/src/libmlk-rpg/rpg/map-file.c Wed Oct 12 15:06:18 2022 +0200 +++ b/src/libmlk-rpg/rpg/map-file.c Wed Oct 12 15:26:12 2022 +0200 @@ -24,7 +24,7 @@ #include <stdlib.h> #include <string.h> -#include <port/port.h> +#include <util/util.h> #include <core/alloc.h> #include <core/error.h> @@ -224,8 +224,8 @@ char line[1024]; char basedir[PATH_MAX]; - port_strlcpy(basedir, path, sizeof (basedir)); - port_strlcpy(ctx->basedir, port_dirname(basedir), sizeof (ctx->basedir)); + util_strlcpy(basedir, path, sizeof (basedir)); + util_strlcpy(ctx->basedir, util_dirname(basedir), sizeof (ctx->basedir)); while (fgets(line, sizeof (line), ctx->fp)) { /* Remove \n if any */
--- a/src/libmlk-rpg/rpg/save.c Wed Oct 12 15:06:18 2022 +0200 +++ b/src/libmlk-rpg/rpg/save.c Wed Oct 12 15:26:12 2022 +0200 @@ -23,7 +23,7 @@ #include <sqlite3.h> -#include <port/port.h> +#include <util/util.h> #include <core/error.h> #include <core/sys.h> @@ -139,7 +139,7 @@ char *str = va_arg(ap, char *); size_t max = va_arg(ap, size_t); - port_strlcpy(str, (const char *)sqlite3_column_text(stmt->handle, c++), max); + util_strlcpy(str, (const char *)sqlite3_column_text(stmt->handle, c++), max); break; } case 't':
--- a/src/libmlk-rpg/rpg/tileset-file.c Wed Oct 12 15:06:18 2022 +0200 +++ b/src/libmlk-rpg/rpg/tileset-file.c Wed Oct 12 15:26:12 2022 +0200 @@ -24,7 +24,7 @@ #include <stdlib.h> #include <string.h> -#include <port/port.h> +#include <util/util.h> #include <core/alloc.h> #include <core/animation.h> @@ -272,8 +272,8 @@ char line[1024]; char basedir[PATH_MAX]; - port_strlcpy(basedir, path, sizeof (basedir)); - port_strlcpy(ctx->basedir, port_dirname(basedir), sizeof (ctx->basedir)); + util_strlcpy(basedir, path, sizeof (basedir)); + util_strlcpy(ctx->basedir, util_dirname(basedir), sizeof (ctx->basedir)); while (fgets(line, sizeof (line), ctx->fp)) { /* Remove \n if any */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/libmlk-util/util/fmemopen.c Wed Oct 12 15:26:12 2022 +0200 @@ -0,0 +1,75 @@ +/* + * fmemopen.h -- fmemopen polyfill + * + * Copyright (c) 2020-2022 David Demelier <markand@malikania.fr> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "util.h" + +#if !defined(MLK_HAS_FMEMOPEN) + +#include <sys/stat.h> +#include <sys/types.h> +#include <fcntl.h> +#include <io.h> +#include <share.h> +#include <stdio.h> +#include <string.h> +#include <windows.h> + +FILE * +util_fmemopen(void *buf, size_t size, const char *mode) +{ + char temppath[MAX_PATH + 1], filename[MAX_PATH + 1]; + FILE *fp; + int fd, flags; + + flags = _O_CREAT | + _O_SHORT_LIVED | + _O_TEMPORARY | + _O_RDWR | + _O_NOINHERIT; + + if (strchr(mode, 'b')) + flags |= _O_BINARY; + + if (!GetTempPath(sizeof (temppath), temppath)) + return NULL; + if (!GetTempFileName(temppath, "MLK", 0, filename)) + return NULL; + if ((fd = _sopen(temppath, flags, _SH_DENYRW, _S_IREAD | _S_IWRITE)) < 0) + return NULL; + if (!(fp = _fdopen(fd, mode))) { + _close(fd); + return NULL; + } + + fwrite(buf, size, 1, fp); + rewind(fp); + + return fp; +} + +#else /* !MLK_HAS_FMEMOPEN */ + +#include <stdio.h> + +FILE * +util_fmemopen(void *buf, size_t len, const char *type) +{ + return fmemopen(buf, len, type); +} + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/libmlk-util/util/openbsd/basename.c Wed Oct 12 15:26:12 2022 +0200 @@ -0,0 +1,68 @@ +/* $OpenBSD: basename.c,v 1.17 2020/10/20 19:30:14 naddy Exp $ */ + +/* + * Copyright (c) 1997, 2004 Todd C. Miller <millert@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <errno.h> +#include <limits.h> +#include <string.h> + +#ifndef PATH_MAX +# define PATH_MAX 2048 +#endif + +char * +util_basename(char *path) +{ + static char bname[PATH_MAX]; + size_t len; + const char *endp, *startp; + + /* Empty or NULL string gets treated as "." */ + if (path == NULL || *path == '\0') { + bname[0] = '.'; + bname[1] = '\0'; + return (bname); + } + + /* Strip any trailing slashes */ + endp = path + strlen(path) - 1; + while (endp > path && *endp == '/') + endp--; + + /* All slashes becomes "/" */ + if (endp == path && *endp == '/') { + bname[0] = '/'; + bname[1] = '\0'; + return (bname); + } + + /* Find the start of the base */ + startp = endp; + while (startp > path && *(startp - 1) != '/') + startp--; + + len = endp - startp + 1; + if (len >= sizeof(bname)) { +#if defined(ENAMETOOLONG) + errno = ENAMETOOLONG; +#endif + return (NULL); + } + memcpy(bname, startp, len); + bname[len] = '\0'; + return (bname); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/libmlk-util/util/openbsd/dirname.c Wed Oct 12 15:26:12 2022 +0200 @@ -0,0 +1,72 @@ +/* $OpenBSD: dirname.c,v 1.17 2020/10/20 19:30:14 naddy Exp $ */ + +/* + * Copyright (c) 1997, 2004 Todd C. Miller <millert@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <errno.h> +#include <limits.h> +#include <string.h> + +#ifndef PATH_MAX +# define PATH_MAX 2048 +#endif + +char * +util_dirname(char *path) +{ + static char dname[PATH_MAX]; + size_t len; + const char *endp; + + /* Empty or NULL string gets treated as "." */ + if (path == NULL || *path == '\0') { + dname[0] = '.'; + dname[1] = '\0'; + return (dname); + } + + /* Strip any trailing slashes */ + endp = path + strlen(path) - 1; + while (endp > path && *endp == '/') + endp--; + + /* Find the start of the dir */ + while (endp > path && *endp != '/') + endp--; + + /* Either the dir is "/" or there are no slashes */ + if (endp == path) { + dname[0] = *endp == '/' ? '/' : '.'; + dname[1] = '\0'; + return (dname); + } else { + /* Move forward past the separating slashes */ + do { + endp--; + } while (endp > path && *endp == '/'); + } + + len = endp - path + 1; + if (len >= sizeof(dname)) { +#if defined(ENAMETOOLONG) + errno = ENAMETOOLONG; +#endif + return (NULL); + } + memcpy(dname, path, len); + dname[len] = '\0'; + return (dname); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/libmlk-util/util/openbsd/getopt.c Wed Oct 12 15:26:12 2022 +0200 @@ -0,0 +1,108 @@ +/* + * Copyright (c) 1987, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +int util_opterr = 1, /* if error message should be printed */ + util_optind = 1, /* index into parent argv vector */ + util_optopt, /* character checked for validity */ + util_optreset; /* reset getopt */ +char *util_optarg; /* argument associated with option */ + +#define BADCH (int)'?' +#define BADARG (int)':' +#define EMSG "" + +/* + * getopt -- + * Parse argc/argv argument vector. + */ +int +util_getopt(int nargc, char * const *nargv, const char *ostr) +{ + static char *place = EMSG; /* option letter processing */ + char *oli; /* option letter list index */ + + if (ostr == NULL) + return (-1); + + if (util_optreset || !*place) { /* update scanning pointer */ + util_optreset = 0; + if (util_optind >= nargc || *(place = nargv[util_optind]) != '-') { + place = EMSG; + return (-1); + } + if (place[1] && *++place == '-') { /* found "--" */ + ++util_optind; + place = EMSG; + return (-1); + } + } /* option letter okay? */ + if ((util_optopt = (int)*place++) == (int)':' || + !(oli = strchr(ostr, util_optopt))) { + /* + * if the user didn't specify '-' as an option, + * assume it means -1. + */ + if (util_optopt == (int)'-') + return (-1); + if (!*place) + ++util_optind; + if (util_opterr && *ostr != ':') + (void)fprintf(stderr, + "illegal option -- %c\n", util_optopt); + return (BADCH); + } + if (*++oli != ':') { /* don't need argument */ + util_optarg = NULL; + if (!*place) + ++util_optind; + } + else { /* need an argument */ + if (*place) /* no white space */ + util_optarg = place; + else if (nargc <= ++util_optind) { /* no arg */ + place = EMSG; + if (*ostr == ':') + return (BADARG); + if (util_opterr) + (void)fprintf(stderr, + "option requires an argument -- %c\n", + util_optopt); + return (BADCH); + } + else /* white space */ + util_optarg = nargv[util_optind]; + place = EMSG; + ++util_optind; + } + return (util_optopt); /* dump back option letter */ +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/libmlk-util/util/openbsd/strlcat.c Wed Oct 12 15:26:12 2022 +0200 @@ -0,0 +1,55 @@ +/* $OpenBSD: strlcat.c,v 1.19 2019/01/25 00:19:25 millert Exp $ */ + +/* + * Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <stddef.h> +#include <string.h> + +/* + * Appends src to string dst of size dsize (unlike strncat, dsize is the + * full size of dst, not space left). At most dsize-1 characters + * will be copied. Always NUL terminates (unless dsize <= strlen(dst)). + * Returns strlen(src) + MIN(dsize, strlen(initial dst)). + * If retval >= dsize, truncation occurred. + */ +size_t +util_strlcat(char *dst, const char *src, size_t dsize) +{ + const char *odst = dst; + const char *osrc = src; + size_t n = dsize; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end. */ + while (n-- != 0 && *dst != '\0') + dst++; + dlen = dst - odst; + n = dsize - dlen; + + if (n-- == 0) + return(dlen + strlen(src)); + while (*src != '\0') { + if (n != 0) { + *dst++ = *src; + n--; + } + src++; + } + *dst = '\0'; + + return(dlen + (src - osrc)); /* count does not include NUL */ +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/libmlk-util/util/openbsd/strlcpy.c Wed Oct 12 15:26:12 2022 +0200 @@ -0,0 +1,49 @@ +/* $OpenBSD: strlcpy.c,v 1.16 2019/01/25 00:19:25 millert Exp $ */ + +/* + * Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <stddef.h> + +/* + * Copy string src to buffer dst of size dsize. At most dsize-1 + * chars will be copied. Always NUL terminates (unless dsize == 0). + * Returns strlen(src); if retval >= dsize, truncation occurred. + */ +size_t +util_strlcpy(char *dst, const char *src, size_t dsize) +{ + const char *osrc = src; + size_t nleft = dsize; + + /* Copy as many bytes as will fit. */ + if (nleft != 0) { + while (--nleft != 0) { + if ((*dst++ = *src++) == '\0') + break; + } + } + + /* Not enough room in dst, add NUL and traverse rest of src. */ + if (nleft == 0) { + if (dsize != 0) + *dst = '\0'; /* NUL-terminate dst */ + while (*src++) + ; + } + + return(src - osrc - 1); /* count does not include NUL */ +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/libmlk-util/util/util.h Wed Oct 12 15:26:12 2022 +0200 @@ -0,0 +1,96 @@ +/* + * util.h -- miscellaneous utilities + * + * Copyright (c) 2020-2022 David Demelier <markand@malikania.fr> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MLK_PORT_H +#define MLK_PORT_H + +#include <limits.h> +#include <stdio.h> + +/* + * This file helps finding what are the available features accross the various + * operating system in the landscape. + * + * The following macros are automatically set depending on the operating + * system: + * + * - MLK_OS_WINDOWS: running on any Windows machine + * - MLK_OS_POSIX: every mostly POSIX systems + * + * The following macro will be automatically defined unless the user override + * them: + * + * - MLK_HAS_FMEMOPEN: defined if fmemopen function is available. + * - MLK_HAS_SSIZE_T: defined if ssize_t typedef is available. + */ + +#if defined(_WIN32) +# define MLK_OS_WINDOWS +#elif defined(__FreeBSD__) +# define MLK_OS_POSIX +#elif defined(__OpenBSD__) +# define MLK_OS_POSIX +#elif defined(__NetBSD__) +# define MLK_OS_POSIX +#elif defined(__linux__) +# define MLK_OS_POSIX +#elif defined(__APPLE__) +# define MLK_OS_POSIX +# define MLK_OS_APPLE +#endif + +#if !defined(PATH_MAX) +# define PATH_MAX 2048 +#endif + +#if defined(MLK_OS_POSIX) && !defined(MLK_HAS_SSIZE_T) +# define MLK_HAS_SSIZE_T +#endif + +#if !defined(MLK_HAS_SSIZE_T) +typedef long long int ssize_t; +#endif + +#if defined(MLK_OS_POSIX) && !defined(MLK_HAS_FMEMOPEN) +# define MLK_HAS_FMEMOPEN +#endif + +size_t +util_strlcpy(char *, const char *, size_t); + +size_t +util_strlcat(char *, const char *, size_t); + +FILE * +util_fmemopen(void *, size_t, const char *); + +char * +util_basename(char *); + +char * +util_dirname(char *); + +extern int util_opterr; +extern int util_optind; +extern int util_optopt; +extern char *util_optarg; + +int +util_getopt(int, char **, const char *); + +#endif /* !MLK_PORT_H */
--- a/src/tools/map/mlk-map.c Wed Oct 12 15:06:18 2022 +0200 +++ b/src/tools/map/mlk-map.c Wed Oct 12 15:26:12 2022 +0200 @@ -26,7 +26,7 @@ #include <jansson.h> -#include <port/port.h> +#include <util/util.h> static void die(const char *fmt, ...) @@ -227,7 +227,7 @@ /* We need to replace the .json extension to .tileset. */ snprintf(path, sizeof (path), "%s", json_string_value(source)); - snprintf(filename, sizeof (filename), "%s", port_basename(path)); + snprintf(filename, sizeof (filename), "%s", util_basename(path)); if (!(ext = strstr(filename, ".json"))) die("could not determine tileset extension");