Compare commits
7 Commits
c9355ad94a
...
57050a83ba
Author | SHA1 | Date |
---|---|---|
|
57050a83ba | |
|
6ed0e84421 | |
|
9b09d2b47a | |
|
1a6c5deb4b | |
|
45a73b00de | |
|
59fff26a5f | |
|
fde4d4662e |
|
@ -0,0 +1,20 @@
|
||||||
|
#!/bin/bash ../install.sh
|
||||||
|
|
||||||
|
NAME='libiconv'
|
||||||
|
VERSION='1.18'
|
||||||
|
DOWNLOAD_URL="https://ftp.gnu.org/pub/gnu/libiconv/libiconv-$VERSION.tar.gz#3b08f5f4f9b4eb82f151a7040bfd6fe6c6fb922efe4b1659c66ea933276965e8"
|
||||||
|
CONFIG_SUB=('build-aux/config.sub' 'libcharset/build-aux/config.sub')
|
||||||
|
CONFIGURE_OPTIONS=(
|
||||||
|
'--disable-nls'
|
||||||
|
'CFLAGS=-std=c11'
|
||||||
|
)
|
||||||
|
|
||||||
|
pre_configure() {
|
||||||
|
echo '#include_next <sys/types.h>' > srclib/sys_types.in.h
|
||||||
|
}
|
||||||
|
|
||||||
|
post_install() {
|
||||||
|
# remove libtool file
|
||||||
|
rm -f $BANAN_SYSROOT/usr/lib/libcharset.la
|
||||||
|
rm -f $BANAN_SYSROOT/usr/lib/libiconv.la
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
diff -ruN libiconv-1.18/configure libiconv-1.18-banan_os/configure
|
||||||
|
--- libiconv-1.18/configure 2024-12-15 13:57:14.000000000 +0200
|
||||||
|
+++ libiconv-1.18-banan_os/configure 2025-08-07 23:49:03.383717069 +0300
|
||||||
|
@@ -8779,6 +8779,10 @@
|
||||||
|
lt_cv_deplibs_check_method=pass_all
|
||||||
|
;;
|
||||||
|
|
||||||
|
+banan_os*)
|
||||||
|
+ lt_cv_deplibs_check_method=pass_all
|
||||||
|
+ ;;
|
||||||
|
+
|
||||||
|
beos*)
|
||||||
|
lt_cv_deplibs_check_method=pass_all
|
||||||
|
;;
|
||||||
|
@@ -14510,6 +14514,16 @@
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
|
||||||
|
+banan_os*)
|
||||||
|
+ version_type=linux # correct to gnu/linux during the next big refactor
|
||||||
|
+ need_lib_prefix=no
|
||||||
|
+ need_version=no
|
||||||
|
+ library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext'
|
||||||
|
+ soname_spec='$libname$release$shared_ext$major'
|
||||||
|
+ dynamic_linker="$host_os DynamicLoader.so"
|
||||||
|
+ shlibpath_var=LD_LIBRARY_PATH
|
||||||
|
+ ;;
|
||||||
|
+
|
||||||
|
beos*)
|
||||||
|
library_names_spec='$libname$shared_ext'
|
||||||
|
dynamic_linker="$host_os ld.so"
|
|
@ -0,0 +1,21 @@
|
||||||
|
diff -ruN libiconv-1.18/srclib/getprogname.c libiconv-1.18-banan_os/srclib/getprogname.c
|
||||||
|
--- libiconv-1.18/srclib/getprogname.c 2024-07-12 14:55:16.000000000 +0300
|
||||||
|
+++ libiconv-1.18-banan_os/srclib/getprogname.c 2025-08-07 23:42:50.691745454 +0300
|
||||||
|
@@ -50,7 +50,7 @@
|
||||||
|
# include <sys/procfs.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
-#if defined __SCO_VERSION__ || defined __sysv5__
|
||||||
|
+#if defined __SCO_VERSION__ || defined __sysv5__ || defined __banan_os__
|
||||||
|
# include <fcntl.h>
|
||||||
|
# include <string.h>
|
||||||
|
#endif
|
||||||
|
@@ -265,7 +265,7 @@
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
-# elif defined __SCO_VERSION__ || defined __sysv5__ /* SCO OpenServer6/UnixWare */
|
||||||
|
+# elif defined __SCO_VERSION__ || defined __sysv5__ || defined __banan_os__ /* SCO OpenServer6/UnixWare */
|
||||||
|
char buf[80];
|
||||||
|
int fd;
|
||||||
|
sprintf (buf, "/proc/%d/cmdline", getpid());
|
|
@ -13,10 +13,6 @@ CONFIGURE_OPTIONS=(
|
||||||
'CFLAGS=-std=c11'
|
'CFLAGS=-std=c11'
|
||||||
)
|
)
|
||||||
|
|
||||||
pre_configure() {
|
|
||||||
unset CC CXX LD
|
|
||||||
}
|
|
||||||
|
|
||||||
post_install() {
|
post_install() {
|
||||||
if [ ! -f ../eawpats.zip ]; then
|
if [ ! -f ../eawpats.zip ]; then
|
||||||
wget https://www.quaddicted.com/files/idgames/sounds/eawpats.zip -O ../eawpats.zip || exit 1
|
wget https://www.quaddicted.com/files/idgames/sounds/eawpats.zip -O ../eawpats.zip || exit 1
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
diff -ruN TiMidity++-2.15.0/timidity/Makefile.in TiMidity++-2.15.0-banan_os/timidity/Makefile.in
|
||||||
|
--- TiMidity++-2.15.0/timidity/Makefile.in 2018-08-29 02:33:39.000000000 +0300
|
||||||
|
+++ TiMidity++-2.15.0-banan_os/timidity/Makefile.in 2025-08-13 12:15:16.535813960 +0300
|
||||||
|
@@ -1956,8 +1956,6 @@
|
||||||
|
version.$(OBJEXT): version.c ../configure
|
||||||
|
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(CFLAGS) -c $(srcdir)/version.c
|
||||||
|
|
||||||
|
-resample.c: newton_table.c
|
||||||
|
-
|
||||||
|
@VCPP_TRUE@newton_table.c: calcnewt$(EXEEXT)
|
||||||
|
@VCPP_TRUE@ ./calcnewt $@
|
||||||
|
|
||||||
|
diff -ruN TiMidity++-2.15.0/timidity/resample.c TiMidity++-2.15.0-banan_os/timidity/resample.c
|
||||||
|
--- TiMidity++-2.15.0/timidity/resample.c 2011-12-03 17:49:20.000000000 +0200
|
||||||
|
+++ TiMidity++-2.15.0-banan_os/timidity/resample.c 2025-08-13 12:16:23.639349203 +0300
|
||||||
|
@@ -46,7 +46,6 @@
|
||||||
|
|
||||||
|
/* for start/end of samples */
|
||||||
|
static float newt_coeffs[58][58] = {
|
||||||
|
-#include "newton_table.c"
|
||||||
|
};
|
||||||
|
|
||||||
|
int sample_bounds_min, sample_bounds_max; /* min/max bounds for sample data */
|
||||||
|
@@ -468,7 +467,6 @@
|
||||||
|
gauss_table[0] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
-#if 0 /* NOT USED */
|
||||||
|
/* the was calculated statically in newton_table.c */
|
||||||
|
static void initialize_newton_coeffs(void)
|
||||||
|
{
|
||||||
|
@@ -499,12 +497,11 @@
|
||||||
|
for (j = 0, sign = pow(-1, i); j <= i; j++, sign *= -1)
|
||||||
|
newt_coeffs[i][j] *= sign;
|
||||||
|
}
|
||||||
|
-#endif /* NOT USED */
|
||||||
|
|
||||||
|
/* initialize the coefficients of the current resampling algorithm */
|
||||||
|
void initialize_resampler_coeffs(void)
|
||||||
|
{
|
||||||
|
- /* initialize_newton_coeffs(); */
|
||||||
|
+ initialize_newton_coeffs();
|
||||||
|
initialize_gauss_table(gauss_n);
|
||||||
|
/* we don't have to initialize newton table any more */
|
||||||
|
|
|
@ -12,6 +12,7 @@ set(LIBC_SOURCES
|
||||||
fenv.cpp
|
fenv.cpp
|
||||||
fnmatch.cpp
|
fnmatch.cpp
|
||||||
ftw.cpp
|
ftw.cpp
|
||||||
|
getopt.cpp
|
||||||
grp.cpp
|
grp.cpp
|
||||||
ifaddrs.cpp
|
ifaddrs.cpp
|
||||||
inttypes.cpp
|
inttypes.cpp
|
||||||
|
|
|
@ -0,0 +1,194 @@
|
||||||
|
#include <assert.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
char* optarg = nullptr;
|
||||||
|
int opterr = 1;
|
||||||
|
int optind = 1;
|
||||||
|
int optopt = 0;
|
||||||
|
|
||||||
|
static int s_idx_in_arg = -1;
|
||||||
|
static int s_old_optind = 1;
|
||||||
|
|
||||||
|
static int getopt_long_impl(int argc, char* const argv[], const char* optstring, const struct option* longopts, int* longindex, bool need_double_hyphen)
|
||||||
|
{
|
||||||
|
if (optind >= argc)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (optind == 0)
|
||||||
|
{
|
||||||
|
s_old_optind = -1;
|
||||||
|
s_idx_in_arg = -1;
|
||||||
|
optind = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* curr = argv[optind];
|
||||||
|
if (curr == nullptr || curr[0] != '-' || curr[1] == '\0')
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (curr[1] == '-' && curr[2] == '\0')
|
||||||
|
{
|
||||||
|
optind++;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s_old_optind != optind)
|
||||||
|
s_idx_in_arg = -1;
|
||||||
|
struct dummy { ~dummy() { s_old_optind = optind; }} _;
|
||||||
|
|
||||||
|
if (s_idx_in_arg == -1 && (!need_double_hyphen || curr[1] == '-'))
|
||||||
|
{
|
||||||
|
for (size_t i = 0; longopts[i].name; i++)
|
||||||
|
{
|
||||||
|
const auto& opt = longopts[i];
|
||||||
|
const size_t name_len = strlen(opt.name);
|
||||||
|
if (strncmp(curr + 2, opt.name, name_len) != 0)
|
||||||
|
continue;
|
||||||
|
if (curr[2 + name_len] != '=' && curr[2 + name_len] != '\0')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
bool has_argument;
|
||||||
|
switch (opt.has_arg)
|
||||||
|
{
|
||||||
|
case no_argument:
|
||||||
|
has_argument = false;
|
||||||
|
break;
|
||||||
|
case required_argument:
|
||||||
|
has_argument = true;
|
||||||
|
break;
|
||||||
|
case optional_argument:
|
||||||
|
has_argument = (curr[2 + name_len] == '=')
|
||||||
|
|| (optind + 1 < argc && argv[optind + 1][0] != '-');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!has_argument)
|
||||||
|
{
|
||||||
|
if (curr[2 + name_len] == '=')
|
||||||
|
{
|
||||||
|
if (opterr && optstring[0] != ':')
|
||||||
|
fprintf(stderr, "%s: option takes no argument -- %.*s\n", argv[0], static_cast<int>(name_len), curr + 2);
|
||||||
|
optind++;
|
||||||
|
return (optstring[0] == ':') ? ':' : '?';
|
||||||
|
}
|
||||||
|
optarg = nullptr;
|
||||||
|
optind++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (curr[2 + name_len] == '=')
|
||||||
|
{
|
||||||
|
optarg = const_cast<char*>(curr + 2 + name_len + 1);
|
||||||
|
optind++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (optind + 1 >= argc)
|
||||||
|
{
|
||||||
|
if (opterr && optstring[0] != ':')
|
||||||
|
fprintf(stderr, "%s: option requires an argument -- %.*s\n", argv[0], static_cast<int>(name_len), curr + 2);
|
||||||
|
optind++;
|
||||||
|
return (optstring[0] == ':') ? ':' : '?';
|
||||||
|
}
|
||||||
|
optarg = argv[optind + 1];
|
||||||
|
optind += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (longindex != nullptr)
|
||||||
|
*longindex = i;
|
||||||
|
|
||||||
|
if (opt.flag == nullptr)
|
||||||
|
return opt.val;
|
||||||
|
*opt.flag = opt.val;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (curr[1] == '-')
|
||||||
|
{
|
||||||
|
if (opterr && optstring[0] != ':')
|
||||||
|
fprintf(stderr, "%s: illegal option -- %s\n", argv[0], curr + 2);
|
||||||
|
optind++;
|
||||||
|
return '?';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s_idx_in_arg == -1)
|
||||||
|
s_idx_in_arg = 1;
|
||||||
|
|
||||||
|
for (size_t i = 0; optstring[i]; i++)
|
||||||
|
{
|
||||||
|
if (optstring[i] == ':')
|
||||||
|
continue;
|
||||||
|
if (curr[s_idx_in_arg] != optstring[i])
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const bool has_argument = (optstring[i + 1] == ':');
|
||||||
|
if (!has_argument)
|
||||||
|
{
|
||||||
|
s_idx_in_arg++;
|
||||||
|
if (curr[s_idx_in_arg] == '\0')
|
||||||
|
{
|
||||||
|
s_idx_in_arg = -1;
|
||||||
|
optind++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (curr[s_idx_in_arg + 1] != '\0')
|
||||||
|
{
|
||||||
|
optarg = const_cast<char*>(curr + s_idx_in_arg + 1);
|
||||||
|
optind++;
|
||||||
|
s_idx_in_arg = -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (optind + 1 >= argc)
|
||||||
|
{
|
||||||
|
if (opterr && optstring[0] != ':')
|
||||||
|
fprintf(stderr, "%s: option requires an argument -- %c\n", argv[0], optstring[i]);
|
||||||
|
optopt = optstring[i];
|
||||||
|
optind++;
|
||||||
|
return optstring[0] == ':' ? ':' : '?';
|
||||||
|
}
|
||||||
|
optarg = const_cast<char*>(argv[optind + 1]);
|
||||||
|
optind += 2;
|
||||||
|
s_idx_in_arg = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return optstring[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opterr && optstring[0] != ':')
|
||||||
|
fprintf(stderr, "%s: illegal option -- %c\n", argv[0], curr[s_idx_in_arg]);
|
||||||
|
optopt = curr[s_idx_in_arg];
|
||||||
|
|
||||||
|
s_idx_in_arg++;
|
||||||
|
if (curr[s_idx_in_arg] == '\0')
|
||||||
|
{
|
||||||
|
s_idx_in_arg = -1;
|
||||||
|
optind++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return '?';
|
||||||
|
}
|
||||||
|
|
||||||
|
int getopt(int argc, char* const argv[], const char* optstring)
|
||||||
|
{
|
||||||
|
struct option option {};
|
||||||
|
return getopt_long_impl(argc, argv, optstring, &option, nullptr, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
int getopt_long(int argc, char* argv[], const char* optstring, const struct option* longopts, int* longindex)
|
||||||
|
{
|
||||||
|
return getopt_long_impl(argc, argv, optstring, longopts, longindex, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
int getopt_long_only(int argc, char* argv[], const char* optstring, const struct option* longopts, int* longindex)
|
||||||
|
{
|
||||||
|
return getopt_long_impl(argc, argv, optstring, longopts, longindex, false);
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
#ifndef _BITS_GETOPT_H
|
||||||
|
#define _BITS_GETOPT_H 1
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
|
||||||
|
int getopt(int argc, char* const argv[], const char* optstring);
|
||||||
|
|
||||||
|
extern char* optarg;
|
||||||
|
extern int opterr, optind, optopt;
|
||||||
|
|
||||||
|
__END_DECLS
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,27 @@
|
||||||
|
#ifndef _GETOPT_H
|
||||||
|
#define _GETOPT_H 1
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
|
||||||
|
#include <bits/getopt.h>
|
||||||
|
|
||||||
|
struct option
|
||||||
|
{
|
||||||
|
const char* name;
|
||||||
|
int has_arg;
|
||||||
|
int* flag;
|
||||||
|
int val;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define no_argument 0
|
||||||
|
#define required_argument 1
|
||||||
|
#define optional_argument 2
|
||||||
|
|
||||||
|
int getopt_long(int argc, char* argv[], const char* optstring, const struct option* longopts, int* longindex);
|
||||||
|
int getopt_long_only(int argc, char* argv[], const char* optstring, const struct option* longopts, int* longindex);
|
||||||
|
|
||||||
|
__END_DECLS
|
||||||
|
|
||||||
|
#endif
|
|
@ -22,12 +22,12 @@ __BEGIN_DECLS
|
||||||
#define GLOB_NOMATCH 2
|
#define GLOB_NOMATCH 2
|
||||||
#define GLOB_NOSPACE 3
|
#define GLOB_NOSPACE 3
|
||||||
|
|
||||||
struct glob_t
|
typedef struct
|
||||||
{
|
{
|
||||||
size_t gl_pathc; /* Count of paths matched by pattern. */
|
size_t gl_pathc; /* Count of paths matched by pattern. */
|
||||||
char** gl_pathv; /* Pointer to a list of matched pathnames. */
|
char** gl_pathv; /* Pointer to a list of matched pathnames. */
|
||||||
size_t gl_offs; /* Slots to reserve at the beginning of gl_pathv. */
|
size_t gl_offs; /* Slots to reserve at the beginning of gl_pathv. */
|
||||||
};
|
} glob_t;
|
||||||
|
|
||||||
int glob(const char* __restrict pattern, int flags, int (*errfunc)(const char* epath, int eerrno), glob_t* __restrict pglob);
|
int glob(const char* __restrict pattern, int flags, int (*errfunc)(const char* epath, int eerrno), glob_t* __restrict pglob);
|
||||||
void globfree(glob_t* pglob);
|
void globfree(glob_t* pglob);
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
#ifndef _ICONV_H
|
|
||||||
#define _ICONV_H 1
|
|
||||||
|
|
||||||
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/iconv.h.html
|
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
|
||||||
|
|
||||||
__BEGIN_DECLS
|
|
||||||
|
|
||||||
#define __need_size_t
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
typedef void* iconv_t;
|
|
||||||
|
|
||||||
size_t iconv(iconv_t cd, char** __restrict inbuf, size_t* __restrict inbytesleft, char** __restrict outbuf, size_t* __restrict outbytesleft);
|
|
||||||
int iconv_close(iconv_t cd);
|
|
||||||
iconv_t iconv_open(const char* tocode, const char* fromcode);
|
|
||||||
|
|
||||||
__END_DECLS
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -125,11 +125,13 @@ struct linger
|
||||||
#define AF_INET 1
|
#define AF_INET 1
|
||||||
#define AF_INET6 2
|
#define AF_INET6 2
|
||||||
#define AF_UNIX 3
|
#define AF_UNIX 3
|
||||||
|
#define AF_LOCAL AF_UNIX
|
||||||
|
|
||||||
#define PF_UNSPEC AF_UNSPEC
|
#define PF_UNSPEC AF_UNSPEC
|
||||||
#define PF_INET AF_INET
|
#define PF_INET AF_INET
|
||||||
#define PF_INET6 AF_INET6
|
#define PF_INET6 AF_INET6
|
||||||
#define PF_UNIX AF_UNIX
|
#define PF_UNIX AF_UNIX
|
||||||
|
#define PF_LOCAL AF_LOCAL
|
||||||
|
|
||||||
#define SHUT_RD 0x01
|
#define SHUT_RD 0x01
|
||||||
#define SHUT_WR 0x02
|
#define SHUT_WR 0x02
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef _TIME_H
|
#ifndef _TIME_H
|
||||||
#define _TIME_H 1
|
#define _TIME_H 1
|
||||||
|
|
||||||
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/time.h.html
|
// https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/time.h.html
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
|
@ -24,15 +24,17 @@ struct sigevent;
|
||||||
|
|
||||||
struct tm
|
struct tm
|
||||||
{
|
{
|
||||||
int tm_sec; /* Seconds [0,60]. */
|
int tm_sec; /* Seconds [0,60]. */
|
||||||
int tm_min; /* Minutes [0,59]. */
|
int tm_min; /* Minutes [0,59]. */
|
||||||
int tm_hour; /* Hour [0,23]. */
|
int tm_hour; /* Hour [0,23]. */
|
||||||
int tm_mday; /* Day of month [1,31]. */
|
int tm_mday; /* Day of month [1,31]. */
|
||||||
int tm_mon; /* Month of year [0,11]. */
|
int tm_mon; /* Month of year [0,11]. */
|
||||||
int tm_year; /* Years since 1900. */
|
int tm_year; /* Years since 1900. */
|
||||||
int tm_wday; /* Day of week [0,6] (Sunday =0). */
|
int tm_wday; /* Day of week [0,6] (Sunday =0). */
|
||||||
int tm_yday; /* Day of year [0,365]. */
|
int tm_yday; /* Day of year [0,365]. */
|
||||||
int tm_isdst; /* Daylight Savings flag. */
|
int tm_isdst; /* Daylight Saving flag. */
|
||||||
|
long tm_gmtoff; /* Seconds east of UTC. */
|
||||||
|
const char* tm_zone; /* Timezone abbreviation */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct timespec
|
struct timespec
|
||||||
|
|
|
@ -124,6 +124,8 @@ __BEGIN_DECLS
|
||||||
#define __need_useconds_t
|
#define __need_useconds_t
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <bits/getopt.h>
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
_CS_PATH = 1,
|
_CS_PATH = 1,
|
||||||
|
@ -547,7 +549,6 @@ long gethostid(void);
|
||||||
int gethostname(char* name, size_t namelen);
|
int gethostname(char* name, size_t namelen);
|
||||||
char* getlogin(void);
|
char* getlogin(void);
|
||||||
int getlogin_r(char* name, size_t namesize);
|
int getlogin_r(char* name, size_t namesize);
|
||||||
int getopt(int argc, char* const argv[], const char* optstring);
|
|
||||||
pid_t getpgid(pid_t pid);
|
pid_t getpgid(pid_t pid);
|
||||||
pid_t getpgrp(void);
|
pid_t getpgrp(void);
|
||||||
pid_t getpid(void);
|
pid_t getpid(void);
|
||||||
|
@ -600,9 +601,6 @@ int chroot(const char* path);
|
||||||
int getpagesize(void);
|
int getpagesize(void);
|
||||||
char* getpass(const char* prompt);
|
char* getpass(const char* prompt);
|
||||||
|
|
||||||
extern char* optarg;
|
|
||||||
extern int opterr, optind, optopt;
|
|
||||||
|
|
||||||
long syscall(long syscall, ...);
|
long syscall(long syscall, ...);
|
||||||
|
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
|
@ -108,53 +108,59 @@ static constexpr bool is_leap_year(uint64_t year)
|
||||||
|
|
||||||
time_t mktime(struct tm* tm)
|
time_t mktime(struct tm* tm)
|
||||||
{
|
{
|
||||||
if (tm->tm_year < 70)
|
tzset();
|
||||||
|
|
||||||
|
struct tm modified = *tm;
|
||||||
|
|
||||||
|
if (modified.tm_year < 70)
|
||||||
{
|
{
|
||||||
errno = EOVERFLOW;
|
errno = EOVERFLOW;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
tm->tm_min += tm->tm_sec / 60;
|
modified.tm_min += modified.tm_sec / 60;
|
||||||
tm->tm_sec %= 60;
|
modified.tm_sec %= 60;
|
||||||
|
|
||||||
tm->tm_hour += tm->tm_min / 60;
|
modified.tm_hour += modified.tm_min / 60;
|
||||||
tm->tm_min %= 60;
|
modified.tm_min %= 60;
|
||||||
|
|
||||||
tm->tm_mday += tm->tm_hour / 24;
|
modified.tm_mday += modified.tm_hour / 24;
|
||||||
tm->tm_hour %= 24;
|
modified.tm_hour %= 24;
|
||||||
|
|
||||||
static constexpr int month_days[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
static constexpr int month_days[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
int days_in_month = month_days[tm->tm_mon];
|
int days_in_month = month_days[modified.tm_mon];
|
||||||
if (tm->tm_mon == 1 && is_leap_year(tm->tm_year))
|
if (modified.tm_mon == 1 && is_leap_year(modified.tm_year))
|
||||||
days_in_month++;
|
days_in_month++;
|
||||||
|
|
||||||
if (tm->tm_mday <= days_in_month)
|
if (modified.tm_mday <= days_in_month)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
tm->tm_mday -= days_in_month;
|
modified.tm_mday -= days_in_month;
|
||||||
tm->tm_mon++;
|
modified.tm_mon++;
|
||||||
}
|
}
|
||||||
|
|
||||||
tm->tm_year += tm->tm_mon / 12;
|
modified.tm_year += modified.tm_mon / 12;
|
||||||
tm->tm_mon %= 12;
|
modified.tm_mon %= 12;
|
||||||
|
|
||||||
tm->tm_yday = tm->tm_mday - 1;
|
modified.tm_yday = modified.tm_mday - 1;
|
||||||
for (int i = 0; i < tm->tm_mon; i++)
|
for (int i = 0; i < modified.tm_mon; i++)
|
||||||
tm->tm_yday += month_days[i];
|
modified.tm_yday += month_days[i];
|
||||||
|
|
||||||
const time_t num_febs = (tm->tm_mon > 1) ? tm->tm_year + 1 : tm->tm_year;
|
const time_t num_febs = (modified.tm_mon > 1) ? modified.tm_year + 1 : modified.tm_year;
|
||||||
const time_t leap_years = (num_febs - 69) / 4 - (num_febs - 1) / 100 + (num_febs + 299) / 400;
|
const time_t leap_years = (num_febs - 69) / 4 - (num_febs - 1) / 100 + (num_febs + 299) / 400;
|
||||||
|
|
||||||
const time_t years = tm->tm_year - 70;
|
const time_t years = modified.tm_year - 70;
|
||||||
const time_t days = years * 365 + leap_years + tm->tm_yday;
|
const time_t days = years * 365 + leap_years + modified.tm_yday;
|
||||||
const time_t hours = days * 24 + tm->tm_hour;
|
const time_t hours = days * 24 + modified.tm_hour;
|
||||||
const time_t minutes = hours * 60 + tm->tm_min;
|
const time_t minutes = hours * 60 + modified.tm_min;
|
||||||
const time_t seconds = minutes * 60 + tm->tm_sec;
|
const time_t seconds = minutes * 60 + modified.tm_sec;
|
||||||
|
|
||||||
|
*tm = modified;
|
||||||
tm->tm_wday = (days + 4) % 7;
|
tm->tm_wday = (days + 4) % 7;
|
||||||
|
tm->tm_isdst = daylight;
|
||||||
|
|
||||||
return seconds;
|
return seconds;
|
||||||
}
|
}
|
||||||
|
@ -190,6 +196,9 @@ struct tm* gmtime_r(const time_t* timer, struct tm* __restrict result)
|
||||||
result->tm_year -= 1900;
|
result->tm_year -= 1900;
|
||||||
result->tm_isdst = 0;
|
result->tm_isdst = 0;
|
||||||
|
|
||||||
|
result->tm_gmtoff = 0;
|
||||||
|
result->tm_zone = "UTC";
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -541,91 +541,6 @@ int rmdir(const char* path)
|
||||||
return unlinkat(AT_FDCWD, path, AT_REMOVEDIR);
|
return unlinkat(AT_FDCWD, path, AT_REMOVEDIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* optarg = nullptr;
|
|
||||||
int opterr = 1;
|
|
||||||
int optind = 1;
|
|
||||||
int optopt = 0;
|
|
||||||
|
|
||||||
int getopt(int argc, char* const argv[], const char* optstring)
|
|
||||||
{
|
|
||||||
if (optind >= argc)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
static int idx = 1;
|
|
||||||
const char* current = argv[optind];
|
|
||||||
|
|
||||||
// if "--" is encountered, no more options are parsed
|
|
||||||
if (idx == -1)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
// if current is nullptr, does not start with '-' or is string "-", return -1
|
|
||||||
if (current == nullptr || current[0] != '-' || current[1] == '\0')
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
// if current points to string "--" increment optind and return -1
|
|
||||||
if (current[1] == '-' && current[2] == '\0')
|
|
||||||
{
|
|
||||||
idx = -1;
|
|
||||||
optind++;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; optstring[i]; i++)
|
|
||||||
{
|
|
||||||
if (optstring[i] == ':')
|
|
||||||
continue;
|
|
||||||
if (current[idx] != optstring[i])
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (optstring[i + 1] == ':')
|
|
||||||
{
|
|
||||||
if (current[idx + 1])
|
|
||||||
{
|
|
||||||
optarg = const_cast<char*>(current + idx + 1);
|
|
||||||
optind += 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
optarg = const_cast<char*>(argv[optind + 1]);
|
|
||||||
optind += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
idx = 1;
|
|
||||||
|
|
||||||
if (optind > argc)
|
|
||||||
{
|
|
||||||
if (opterr && optstring[0] != ':')
|
|
||||||
fprintf(stderr, "%s: option requires an argument -- %c\n", argv[0], optstring[i]);
|
|
||||||
optopt = optstring[i];
|
|
||||||
return optstring[0] == ':' ? ':' : '?';
|
|
||||||
}
|
|
||||||
|
|
||||||
return optstring[i];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (current[++idx] == '\0')
|
|
||||||
{
|
|
||||||
idx = 1;
|
|
||||||
optind++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return optstring[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (opterr && optstring[0] != ':')
|
|
||||||
fprintf(stderr, "%s: illegal option -- %c\n", argv[0], current[idx]);
|
|
||||||
|
|
||||||
if (current[++idx] == '\0')
|
|
||||||
{
|
|
||||||
idx = 1;
|
|
||||||
optind++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return '?';
|
|
||||||
}
|
|
||||||
|
|
||||||
int chroot(const char* path)
|
int chroot(const char* path)
|
||||||
{
|
{
|
||||||
return syscall(SYS_CHROOT, path);
|
return syscall(SYS_CHROOT, path);
|
||||||
|
|
Loading…
Reference in New Issue