commit 2a00e21c0c6aadccf2d86abbeaa0252c54ae87db from: Thomas Adam date: Tue Sep 28 23:28:44 2021 UTC portable: initial Linux compilation This commit modifies the GoT main branch to be able to compile it under linux. commit - 22a38a4331904c508c1782e5399680ba7069300f commit + 2a00e21c0c6aadccf2d86abbeaa0252c54ae87db blob - 77545d9856df477c5ddeae71dfd87b886ca169ac blob + 7f071e47983e5c16b505d43745c22c538d3f4f65 --- README.portable +++ README.portable @@ -39,6 +39,7 @@ NOTE: THIS ONLY WORKS AFTER `make install` DUE TO HOW INSTALLATION ============ +<<<<<<< HEAD ``` $ ./autogen.sh $ ./configure && make @@ -58,6 +59,11 @@ sent to the mailing list for review [2] or sent to me The read-only Github repository also runs CI checks using Cirrus-CI on Linux and FreeBSD. +======= + $ autoreconf -i + $ ./configure && make + $ sudo make install +>>>>>>> 74564ec3 (portable: initial Linux compilation) TODO ==== blob - 49f23799a8f498120c8f4e78513e02cfb55f0417 blob + ad09c4c45cacae46aa54ab7a5c0fe217cd577ad4 --- compat/Makefile.am +++ compat/Makefile.am @@ -36,6 +36,8 @@ if HOST_FREEBSD else libopenbsd_compat_a_SOURCES += uuid.c endif + uuid.c \ + xmalloc.c EXTRA_DIST = \ $(top_srcdir)/include/got_compat.h \ blob - /dev/null blob + 4cb3fee954c0994f90c6ad916cce9abc291f8614 (mode 644) --- /dev/null +++ compat/xmalloc.c @@ -0,0 +1,185 @@ +/* $OpenBSD$ */ + +/* + * Author: Tatu Ylonen + * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland + * All rights reserved + * Versions of malloc and friends that check their results, and never return + * failure (they call fatalx if they encounter an error). + * + * As far as I am concerned, the code I have written for this software + * can be used freely for any purpose. Any derived versions of this + * software must be clearly marked as such, and if the derived work is + * incompatible with the protocol description in the RFC file, it must be + * called by a name other than "ssh" or "Secure Shell". + */ + +#include +#include +#include +#include +#include +#include + +#include "got_compat.h" + +#include "xmalloc.h" + +void * +xmalloc(size_t size) +{ + void *ptr; + + if (size == 0) { + fprintf(stderr,"xmalloc: zero size"); + exit (1); + } + ptr = malloc(size); + if (ptr == NULL) { + fprintf(stderr, "xmalloc: allocating %zu bytes: %s", + size, strerror(errno)); + exit (1); + } + return ptr; +} + +void * +xcalloc(size_t nmemb, size_t size) +{ + void *ptr; + + if (size == 0 || nmemb == 0) + fprintf(stderr,"xcalloc: zero size"); + ptr = calloc(nmemb, size); + if (ptr == NULL) { + fprintf(stderr, "xcalloc: allocating %zu * %zu bytes: %s", + nmemb, size, strerror(errno)); + exit (1); + } + return ptr; +} + +void * +xrealloc(void *ptr, size_t size) +{ + return xreallocarray(ptr, 1, size); +} + +void * +xreallocarray(void *ptr, size_t nmemb, size_t size) +{ + void *new_ptr; + + if (nmemb == 0 || size == 0) { + fprintf(stderr, "xreallocarray: zero size"); + exit (1); + } + new_ptr = reallocarray(ptr, nmemb, size); + if (new_ptr == NULL) { + fprintf(stderr, "xreallocarray: allocating %zu * %zu bytes: %s", + nmemb, size, strerror(errno)); + exit (1); + } + return new_ptr; +} + +void * +xrecallocarray(void *ptr, size_t oldnmemb, size_t nmemb, size_t size) +{ + void *new_ptr; + + if (nmemb == 0 || size == 0) { + fprintf(stderr,"xrecallocarray: zero size"); + exit (1); + } + new_ptr = recallocarray(ptr, oldnmemb, nmemb, size); + if (new_ptr == NULL) { + fprintf(stderr,"xrecallocarray: allocating %zu * %zu bytes: %s", + nmemb, size, strerror(errno)); + exit (1); + } + return new_ptr; +} + +char * +xstrdup(const char *str) +{ + char *cp; + + if ((cp = strdup(str)) == NULL) { + fprintf(stderr,"xstrdup: %s", strerror(errno)); + exit (1); + } + return cp; +} + +char * +xstrndup(const char *str, size_t maxlen) +{ + char *cp; + + if ((cp = strndup(str, maxlen)) == NULL) { + fprintf(stderr,"xstrndup: %s", strerror(errno)); + exit (1); + } + return cp; +} + +int +xasprintf(char **ret, const char *fmt, ...) +{ + va_list ap; + int i; + + va_start(ap, fmt); + i = xvasprintf(ret, fmt, ap); + va_end(ap); + + return i; +} + +int +xvasprintf(char **ret, const char *fmt, va_list ap) +{ + int i; + + i = vasprintf(ret, fmt, ap); + + if (i == -1) { + fprintf(stderr,"xasprintf: %s", strerror(errno)); + exit (1); + } + + return i; +} + +int +xsnprintf(char *str, size_t len, const char *fmt, ...) +{ + va_list ap; + int i; + + va_start(ap, fmt); + i = xvsnprintf(str, len, fmt, ap); + va_end(ap); + + return i; +} + +int +xvsnprintf(char *str, size_t len, const char *fmt, va_list ap) +{ + int i; + + if (len > INT_MAX) + fprintf(stderr,"xsnprintf: len > INT_MAX"); + + i = vsnprintf(str, len, fmt, ap); + + if (i < 0 || i >= (int)len) { + fprintf(stderr,"xsnprintf: overflow"); + exit (1); + } + + return i; +} blob - /dev/null blob + 82a5624e6cff0daddb85ad48d75031abf9d728f0 (mode 644) --- /dev/null +++ compat/xmalloc.h @@ -0,0 +1,48 @@ +/* $OpenBSD$ */ + +/* + * Author: Tatu Ylonen + * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland + * All rights reserved + * Created: Mon Mar 20 22:09:17 1995 ylo + * + * Versions of malloc and friends that check their results, and never return + * failure (they call fatal if they encounter an error). + * + * As far as I am concerned, the code I have written for this software + * can be used freely for any purpose. Any derived versions of this + * software must be clearly marked as such, and if the derived work is + * incompatible with the protocol description in the RFC file, it must be + * called by a name other than "ssh" or "Secure Shell". + */ + +#ifndef XMALLOC_H +#define XMALLOC_H + +#include + +#if !defined(__bounded__) +#define __bounded__(x, y, z) +#endif + +void *xmalloc(size_t); +void *xcalloc(size_t, size_t); +void *xrealloc(void *, size_t); +void *xreallocarray(void *, size_t, size_t); +void *xrecallocarray(void *, size_t, size_t, size_t); +char *xstrdup(const char *); +char *xstrndup(const char *, size_t); +int xasprintf(char **, const char *, ...) + __attribute__((__format__ (printf, 2, 3))) + __attribute__((__nonnull__ (2))); +int xvasprintf(char **, const char *, va_list) + __attribute__((__nonnull__ (2))); +int xsnprintf(char *, size_t, const char *, ...) + __attribute__((__format__ (printf, 3, 4))) + __attribute__((__nonnull__ (3))) + __attribute__((__bounded__ (__string__, 1, 2))); +int xvsnprintf(char *, size_t, const char *, va_list) + __attribute__((__nonnull__ (3))) + __attribute__((__bounded__ (__string__, 1, 2))); + +#endif /* XMALLOC_H */ blob - ca029d269ab98c3b9df9a4879cd3e6d884a81b29 blob + c7352e7d1a7fd2efb4a960a825101ff89cc039dd --- libexec/got-index-pack/Makefile.am +++ libexec/got-index-pack/Makefile.am @@ -1,4 +1,5 @@ libexec_PROGRAMS = got-index-pack +bin_PROGRAMS = got-index-pack got_index_pack_SOURCES = got-index-pack.c \ $(top_srcdir)/lib/error.c \ $(top_srcdir)/lib/inflate.c \