Update to gcc11

Change to openssl
Clean up some `C` for HitchHiker specific utils
This commit is contained in:
Nathan Fisher 2022-01-28 11:44:56 -05:00
parent 6f7db66683
commit 2feff2a5d3
26 changed files with 30474 additions and 186 deletions

View File

@ -72,6 +72,7 @@ mpc-${mpc_version}.tar.gz \
mpfr-${mpfr_version}.tar.xz \ mpfr-${mpfr_version}.tar.xz \
musl-$(musl_version).tar.gz \ musl-$(musl_version).tar.gz \
musl-fts-$(musl-fts_version).tar.gz \ musl-fts-$(musl-fts_version).tar.gz \
openssl-${openssl_version}.tar.gz \
ncurses-${ncurses_version}.tar.gz \ ncurses-${ncurses_version}.tar.gz \
netbsd-curses-${netbsd-curses_version}.tar.xz \ netbsd-curses-${netbsd-curses_version}.tar.xz \
ninja-${ninja_version}.tar.gz \ ninja-${ninja_version}.tar.gz \
@ -440,6 +441,11 @@ ninja: ninja-${ninja_version}.tar.gz
ninja-${ninja_version}.tar.gz: ninja-${ninja_version}.tar.gz:
wget -c ${github}/ninja-build/ninja/archive/v${ninja_version}/$@ wget -c ${github}/ninja-build/ninja/archive/v${ninja_version}/$@
openssl: openssl-${openssl_version}.tar.gz
openssl-${openssl_version}.tar.gz:
wget -c https://www.openssl.org/source/$@
patch: patch-${patch_version}.tar.xz patch: patch-${patch_version}.tar.xz
patch-${patch_version}.tar.xz: patch-${patch_version}.tar.xz:

View File

@ -4,7 +4,7 @@
include versions.mk include versions.mk
os_name = Hitch Hiker Linux os_name = Hitch Hiker Linux
os_abbrev = hhl os_abbrev = hhl
os_version = 2021q2 os_version = 2021q4
basedir = /src basedir = /src
include $(basedir)/config.mk include $(basedir)/config.mk
@ -68,7 +68,7 @@ objdir ?= $(global_objdir)/$(distfullname)
tooldir = $(basedir)/build/toolchain-$(arch) tooldir = $(basedir)/build/toolchain-$(arch)
export LC_ALL = POSIX export LC_ALL = POSIX
export PATH = $(tooldir)/bin:$(tooldir)/sbin:/usr/bin:/usr/sbin:/bin:/sbin export PATH = $(tooldir)/bin:$(tooldir)/sbin:/usr/bin:/usr/bin/core_perl:/usr/sbin:/bin:/sbin
_dhcpcd ?= 1 _dhcpcd ?= 1
_wireless ?= 1 _wireless ?= 1

View File

@ -9,7 +9,7 @@ attr_version = 2.4.48
autoconf_version = 2.71 autoconf_version = 2.71
automake_version = 1.16.3 automake_version = 1.16.3
bc_version = 3.2.5 bc_version = 3.2.5
binutils_version = 2.36.1 binutils_version = 2.37
bison_version = 3.7.5 bison_version = 3.7.5
busybox_version = 1.31.1 busybox_version = 1.31.1
bzip2_version = 1.0.8 bzip2_version = 1.0.8
@ -25,11 +25,11 @@ elfutils_version = 0.182
eudev_version = 3.2.9 eudev_version = 3.2.9
execline_version = 2.7.0.1 execline_version = 2.7.0.1
expat_version = 2.2.10 expat_version = 2.2.10
file_version = 5.39 file_version = 5.40
findutils_version = 4.8.0 findutils_version = 4.8.0
flex_version = 2.6.4 flex_version = 2.6.4
gawk_version = 5.1.0 gawk_version = 5.1.1
gcc_version = 10.2.0 gcc_version = 11.2.0
gdbm_version = 1.19 gdbm_version = 1.19
gettext_version = 0.21 gettext_version = 0.21
gettext-tiny_version = 0.3.2 gettext-tiny_version = 0.3.2
@ -38,7 +38,7 @@ gmp_version = 6.2.1
gperf_version = 3.1 gperf_version = 3.1
grep_version = 3.6 grep_version = 3.6
groff_version = 1.22.4 groff_version = 1.22.4
grub_version = 2.04 grub_version = 2.06
gzip_version = 1.10 gzip_version = 1.10
haveged_version = 1.9.14 haveged_version = 1.9.14
iana-etc_version = 20210115 iana-etc_version = 20210115
@ -56,9 +56,9 @@ libnl_version = 3.5.0
libressl_version = 3.0.2 libressl_version = 3.0.2
libtool_version = 2.4.6 libtool_version = 2.4.6
libz_version = 1.2.8.2015.12.26 libz_version = 1.2.8.2015.12.26
linux_version = 5.11.5 linux_version = 5.16.1
linux_rpi_version = 5.4.45 linux_rpi_version = 5.4.45
m4_version = 1.4.18 m4_version = 1.4.19
make_version = 4.3 make_version = 4.3
man-pages_version = 5.10 man-pages_version = 5.10
mandoc_version = 1.14.5 mandoc_version = 1.14.5
@ -67,15 +67,16 @@ mpc_version = 1.2.1
mpfr_version = 4.1.0 mpfr_version = 4.1.0
musl_version = 1.2.2 musl_version = 1.2.2
musl-fts_version = 1.2.7 musl-fts_version = 1.2.7
openssl_version = 3.0.1
ncurses_version = 6.2 ncurses_version = 6.2
netbsd-curses_version = 0.3.1 netbsd-curses_version = 0.3.1
ninja_version = 1.10.2 ninja_version = 1.10.2
patch_version = 2.7.6 patch_version = 2.7.6
pcre_version = 8.44 pcre_version = 8.45
perl_version = 5.32.1 perl_version = 5.32.1
perl-cross_version = 1.3.5 perl-cross_version = 1.3.5
pkg-config_version = 0.29.2 pkg-config_version = 0.29.2
pkgsrc_version = 2020Q2 pkgsrc_version = 2020Q3
procps-ng_version = 3.3.16 procps-ng_version = 3.3.16
psmisc_version = 23.3 psmisc_version = 23.3
python_version = 3.9.1 python_version = 3.9.1
@ -87,13 +88,13 @@ shadow_version = 4.8.1
skalibs_version = 2.10.0.1 skalibs_version = 2.10.0.1
sysklogd_version = 1.5.1 sysklogd_version = 1.5.1
tar_version = 1.33 tar_version = 1.33
texinfo_version = 6.7 texinfo_version = 6.8
tzdata_version = 2021a tzdata_version = 2021a
u-boot_version = 2021.01 u-boot_version = 2021.01
udev-lfs_version = 20171102 udev-lfs_version = 20171102
util-linux_version = 2.36.1 util-linux_version = 2.36.1
vim_version = 8.2.2433 vim_version = 8.2.2433
wget_version = 1.21.1 wget_version = 1.21.2
wireless_tools_version = 29 wireless_tools_version = 29
wpa_supplicant_version = 2.9 wpa_supplicant_version = 2.9
XML-Parser_version = 2.46 XML-Parser_version = 2.46

10438
kernel/config-x86-mine Normal file

File diff suppressed because it is too large Load Diff

9907
kernel/config-x86-mine.old Normal file

File diff suppressed because it is too large Load Diff

9952
kernel/config-x86_64-mine Normal file

File diff suppressed because it is too large Load Diff

View File

@ -17,6 +17,9 @@ endif
ifeq ($(build_python), 1) ifeq ($(build_python), 1)
subdirs += python subdirs += python
endif endif
ifeq ($(build_file), 1)
subdirs += file
endif
subdirs += binutils subdirs += binutils
subdirs += gcc-pass1 subdirs += gcc-pass1
subdirs += linux-headers subdirs += linux-headers

8
toolchain/file/Makefile Normal file
View File

@ -0,0 +1,8 @@
# Makefile - hhl - /usr/src/world/gawk
# Copyright 2020 Nathan Fisher <nfisher.sr@gmail.com>
#
distname = file
distext = gz
include toolchain.mk
config_opts += --disable-nls
include targets.mk

View File

@ -44,10 +44,11 @@ subdirs += expat
subdirs += kmod subdirs += kmod
subdirs += gettext subdirs += gettext
# for musl # for musl
subdirs += argp-standalone #subdirs += argp-standalone
subdirs += elfutils subdirs += elfutils
subdirs += libffi subdirs += libffi
subdirs += libressl #subdirs += libressl
subdirs += openssl
subdirs += wget subdirs += wget
#subdirs += python #subdirs += python
#subdirs += ninja #subdirs += ninja
@ -65,8 +66,6 @@ subdirs += texinfo
subdirs += procps-ng subdirs += procps-ng
subdirs += util-linux subdirs += util-linux
# for musl # for musl
#subdirs += argp-standalone
# for musl
#subdirs += musl-fts #subdirs += musl-fts
subdirs += e2fsprogs subdirs += e2fsprogs
subdirs += haveged subdirs += haveged

View File

@ -29,7 +29,8 @@
#define _GNU_SOURCE // getline, getopt #define _GNU_SOURCE // getline, getopt
#include <ctype.h> // isprint #include <ctype.h> // isprint
#include <err.h> // err #include <err.h> // err, perror
#include <errno.h> // errno
#include <inttypes.h> // uint*_t #include <inttypes.h> // uint*_t
#include <libgen.h> // basename #include <libgen.h> // basename
#include <stdio.h> // fclose, fopen, getline, nread, perror, printf #include <stdio.h> // fclose, fopen, getline, nread, perror, printf
@ -87,6 +88,23 @@ void _head(char *file) {
} }
} }
long parselong(char *buf) {
errno = 0;
char *endptr;
int num = strtol(optarg, &endptr, 10);
if (errno != 0) {
perror("Error parsing integer from input: ");
exit(EXIT_FAILURE);
} else if (num == 0 && endptr == optarg) {
fprintf(stderr, "Error: invalid input: %s\n", optarg);
exit(EXIT_FAILURE);
} else if (*endptr != '\0') {
fprintf(stderr, "Error: invalid input: %s\n", optarg);
exit(EXIT_FAILURE);
}
return num;
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
int c, index; int c, index;
__progname = basename(argv[0]); __progname = basename(argv[0]);
@ -109,7 +127,7 @@ int main(int argc, char *argv[]) {
switch (c) { switch (c) {
case 'c': case 'c':
cflag = 1; cflag = 1;
chars = (int)strtol(optarg, NULL, 10); chars = (int)parselong(optarg);
break; break;
case 'q': case 'q':
qflag = 1; qflag = 1;
@ -124,7 +142,7 @@ int main(int argc, char *argv[]) {
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case 'n': case 'n':
nflag = 1; nflag = 1;
lines = (int)strtol(optarg, NULL, 10); lines = (int)parselong(optarg);
break; break;
case '0': case '0':
case '1': case '1':

View File

@ -28,13 +28,13 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include <sys/param.h> #include <sys/param.h> // HOST_NAME_MAX
#include <libgen.h> #include <libgen.h> // basename
#include <stdio.h> #include <stdio.h> // printf, fprintf
#include <stdlib.h> #include <stdlib.h> // exit
#include <string.h> #include <string.h> // strlen
#include <unistd.h> #include <unistd.h> // gethostname, sethostname, getopt
static const char *__progname; static const char *__progname;

View File

@ -2,6 +2,7 @@
# Copyright 2020 Nathan Fisher <nfisher.sr@gmail.com> # Copyright 2020 Nathan Fisher <nfisher.sr@gmail.com>
# #
distname = gcc distname = gcc
patches = gcc-nostdinc.patch
include world.mk include world.mk
ifeq ($(arch),x86_64) ifeq ($(arch),x86_64)

View File

@ -0,0 +1,11 @@
--- gcc-11.2.0.orig/configure 2021-07-28 02:55:06.628278148 -0400
+++ gcc-11.2.0.new/configure 2021-10-19 11:51:51.300514740 -0400
@@ -16478,7 +16478,7 @@
fi
-RAW_CXX_FOR_TARGET="$CXX_FOR_TARGET"
+RAW_CXX_FOR_TARGET="$CXX_FOR_TARGET -nostdinc++"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking where to find the target ar" >&5
$as_echo_n "checking where to find the target ar... " >&6; }

View File

@ -1,8 +1,7 @@
# Makefile - hhl - /usr/src/world/m4 # Makefile - hhl - /usr/src/world/m4
# Copyright 2020 Nathan Fisher <nfisher.sr@gmail.com> # Copyright 2020 Nathan Fisher <nfisher.sr@gmail.com>
# #
distname = m4 distname = m4
patches = m4-glibc-fixes.patch
include world.mk include world.mk
config_opts += --host=$(tgt) config_opts += --host=$(tgt)
CFLAGS += --sysroot=$(DESTDIR) CFLAGS += --sysroot=$(DESTDIR)

View File

@ -1,107 +0,0 @@
diff -Naur m4-1.4.18.orig/lib/fflush.c m4-1.4.18/lib/fflush.c
--- m4-1.4.18.orig/lib/fflush.c 2016-12-31 08:54:41.000000000 -0500
+++ m4-1.4.18/lib/fflush.c 2020-05-19 16:21:43.578036277 -0400
@@ -33,7 +33,7 @@
#undef fflush
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
/* Clear the stream's ungetc buffer, preserving the value of ftello (fp). */
static void
@@ -72,7 +72,7 @@
#endif
-#if ! (defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */)
+#if ! (defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */)
# if (defined __sferror || defined __DragonFly__ || defined __ANDROID__) && defined __SNPT
/* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Android */
@@ -148,7 +148,7 @@
if (stream == NULL || ! freading (stream))
return fflush (stream);
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
clear_ungetc_buffer_preserving_position (stream);
diff -Naur m4-1.4.18.orig/lib/fpending.c m4-1.4.18/lib/fpending.c
--- m4-1.4.18.orig/lib/fpending.c 2016-12-31 08:54:41.000000000 -0500
+++ m4-1.4.18/lib/fpending.c 2020-05-19 16:21:43.578036277 -0400
@@ -32,7 +32,7 @@
/* Most systems provide FILE as a struct and the necessary bitmask in
<stdio.h>, because they need it for implementing getc() and putc() as
fast macros. */
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
return fp->_IO_write_ptr - fp->_IO_write_base;
#elif defined __sferror || defined __DragonFly__ || defined __ANDROID__
/* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Android */
diff -Naur m4-1.4.18.orig/lib/fpurge.c m4-1.4.18/lib/fpurge.c
--- m4-1.4.18.orig/lib/fpurge.c 2016-12-31 08:54:41.000000000 -0500
+++ m4-1.4.18/lib/fpurge.c 2020-05-19 16:21:43.578036277 -0400
@@ -62,7 +62,7 @@
/* Most systems provide FILE as a struct and the necessary bitmask in
<stdio.h>, because they need it for implementing getc() and putc() as
fast macros. */
-# if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+# if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
fp->_IO_read_end = fp->_IO_read_ptr;
fp->_IO_write_ptr = fp->_IO_write_base;
/* Avoid memory leak when there is an active ungetc buffer. */
diff -Naur m4-1.4.18.orig/lib/freadahead.c m4-1.4.18/lib/freadahead.c
--- m4-1.4.18.orig/lib/freadahead.c 2016-12-31 08:54:41.000000000 -0500
+++ m4-1.4.18/lib/freadahead.c 2020-05-19 16:21:43.578036277 -0400
@@ -25,7 +25,7 @@
size_t
freadahead (FILE *fp)
{
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
if (fp->_IO_write_ptr > fp->_IO_write_base)
return 0;
return (fp->_IO_read_end - fp->_IO_read_ptr)
diff -Naur m4-1.4.18.orig/lib/freading.c m4-1.4.18/lib/freading.c
--- m4-1.4.18.orig/lib/freading.c 2016-12-31 08:54:41.000000000 -0500
+++ m4-1.4.18/lib/freading.c 2020-05-19 16:21:43.578036277 -0400
@@ -31,7 +31,7 @@
/* Most systems provide FILE as a struct and the necessary bitmask in
<stdio.h>, because they need it for implementing getc() and putc() as
fast macros. */
-# if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+# if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
return ((fp->_flags & _IO_NO_WRITES) != 0
|| ((fp->_flags & (_IO_NO_READS | _IO_CURRENTLY_PUTTING)) == 0
&& fp->_IO_read_base != NULL));
diff -Naur m4-1.4.18.orig/lib/fseeko.c m4-1.4.18/lib/fseeko.c
--- m4-1.4.18.orig/lib/fseeko.c 2016-12-31 08:54:41.000000000 -0500
+++ m4-1.4.18/lib/fseeko.c 2020-05-19 16:21:43.578036277 -0400
@@ -47,7 +47,7 @@
#endif
/* These tests are based on fpurge.c. */
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
if (fp->_IO_read_end == fp->_IO_read_ptr
&& fp->_IO_write_ptr == fp->_IO_write_base
&& fp->_IO_save_base == NULL)
@@ -123,7 +123,7 @@
return -1;
}
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
fp->_flags &= ~_IO_EOF_SEEN;
fp->_offset = pos;
#elif defined __sferror || defined __DragonFly__ || defined __ANDROID__
diff -Naur m4-1.4.18.orig/lib/stdio-impl.h m4-1.4.18/lib/stdio-impl.h
--- m4-1.4.18.orig/lib/stdio-impl.h 2016-12-31 08:54:42.000000000 -0500
+++ m4-1.4.18/lib/stdio-impl.h 2020-05-19 16:21:43.601369662 -0400
@@ -138,3 +138,4 @@
# define _IOERR 0x10
#endif
+#define _IO_IN_BACKUP 0x100

37
world/openssl/Makefile Normal file
View File

@ -0,0 +1,37 @@
# Makefile - hhl - /usr/src/world/openssl
# Copyright 2020 Nathan Fisher <nfisher.sr@gmail.com>
#
distname = openssl
distext = gz
include world.mk
config_cmd = cd $(objdir) && $(srcdir)/Configure $(config_opts)
export CFLAGS = --sysroot=$(DESTDIR)
ifeq (aarch64, $(arch))
config_opts += linux-aarch64
endif
ifeq (riscv64, $(arch))
config_opts += linux64-riscv64
endif
ifeq (x86_64, $(arch))
config_opts += linux-x86_64
endif
ifeq ($(filter i486 i586 i686, $(arch)), $(arch))
config_opts += linux-x86
endif
ifeq (i486, $(arch))
export CFLAGS = -latomic
endif
ifeq (armv7l, $(arch))
config_opts += linux-generic32
export CFLAGS = -latomic
endif
config_opts += --cross-compile-prefix=$(tgt)-
config_opts += --openssldir=/etc/ssl
config_opts += --libdir=/usr/lib
config_opts += shared
consif_opts += zlib-dynamic
include targets.mk

View File

@ -28,12 +28,11 @@
#define _GNU_SOURCE #define _GNU_SOURCE
#include <dirent.h> #include <dirent.h> // opendir, rewinddir, readdir
#include <stdio.h> #include <stdio.h> // fopen, fclose, fwrite
#include <stdlib.h> #include <stdlib.h> // exit, srand
#include <string.h> #include <string.h> // strncat, strcmp, strdup
#include <time.h> #include <time.h> // time
#include <unistd.h>
#include "config.h" #include "config.h"

View File

@ -28,12 +28,12 @@
#define _XOPEN_SOURCE #define _XOPEN_SOURCE
#include <err.h> #include <err.h> // err
#include <libgen.h> #include <libgen.h> // basename
#include <stdio.h> #include <stdio.h> // fprintf, puts
#include <stdlib.h> #include <stdlib.h> // exit
#include <string.h> #include <string.h> // strlen, strcmp
#include <unistd.h> #include <unistd.h> // getopt
static const char *__progname; static const char *__progname;

View File

@ -28,12 +28,11 @@
#define _XOPEN_SOURCE #define _XOPEN_SOURCE
#include <err.h> #include <err.h> // err
#include <libgen.h> #include <libgen.h> // basename, dirname
#include <stdio.h> #include <stdio.h> // fprintf, puts
#include <stdlib.h> #include <stdlib.h> // exit
#include <string.h> #include <unistd.h> // getopt
#include <unistd.h>
static const char *__progname; static const char *__progname;

View File

@ -27,11 +27,11 @@
*/ */
#define _XOPEN_SOURCE #define _XOPEN_SOURCE
#include <ctype.h> #include <ctype.h> // isprint
#include <libgen.h> #include <libgen.h> // basename
#include <stdio.h> #include <stdio.h> // fprintf
#include <stdlib.h> #include <stdlib.h> // exit
#include <unistd.h> #include <unistd.h> // getopt, link
static const char *__progname; static const char *__progname;

View File

@ -28,13 +28,13 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include <sys/sysinfo.h> #include <sys/sysinfo.h> // get_nprocs, get_nprocs_conf
#include <ctype.h> #include <ctype.h> // isprint
#include <libgen.h> #include <libgen.h> // basename
#include <stdio.h> #include <stdio.h> // fprintf, printf
#include <stdlib.h> #include <stdlib.h> // exit
#include <unistd.h> #include <unistd.h> // getopt
static const char *__progname; static const char *__progname;

View File

@ -28,13 +28,12 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include <err.h> #include <err.h> // warn
#include <libgen.h> #include <libgen.h> // basename
#include <limits.h> #include <limits.h> // realpath
#include <stdio.h> #include <stdio.h> // fprintf
#include <stdlib.h> #include <stdlib.h> // exit, realpath
#include <string.h> #include <unistd.h> // getopt, access
#include <unistd.h>
static const char *__progname; static const char *__progname;

View File

@ -27,13 +27,14 @@
*/ */
#define _XOPEN_SOURCE #define _XOPEN_SOURCE
#include <ctype.h> #include <ctype.h> // isprint
#include <inttypes.h> #include <errno.h> // errno
#include <libgen.h> #include <stdint.h> // uint8_t
#include <stdio.h> #include <libgen.h> // basename
#include <stdlib.h> #include <stdio.h> // fopen, fclose, fseek, ftell, fflush, fwrite
#include <string.h> #include <stdlib.h> // exit, system
#include <unistd.h> #include <string.h> // strcomp
#include <unistd.h> // getopt
static const char *__progname; static const char *__progname;
const int slice = 4096; // read/write 4k at a time const int slice = 4096; // read/write 4k at a time
@ -95,7 +96,7 @@ int _shredit(char *file, char *dev, unsigned long int _size) {
uint8_t percent; // percentage finished uint8_t percent; // percentage finished
unsigned long int _tsize = (_size); unsigned long int _tsize = (_size);
char *data; // data type char *data; // data type
/* hide the cursor */ /* hide the cursor */
if (vflag) if (vflag)
system("tput civis"); system("tput civis");
@ -204,6 +205,23 @@ int _unlinkit(char *file) {
} }
} }
long parselong(char *buf) {
errno = 0;
char *endptr;
int num = strtol(optarg, &endptr, 10);
if (errno != 0) {
perror("Error parsing integer from input: ");
exit(EXIT_FAILURE);
} else if (num == 0 && endptr == optarg) {
fprintf(stderr, "Error: invalid input: %s\n", optarg);
exit(EXIT_FAILURE);
} else if (*endptr != '\0') {
fprintf(stderr, "Error: invalid input: %s\n", optarg);
exit(EXIT_FAILURE);
}
return num;
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
unsigned int index; unsigned int index;
unsigned int c; unsigned int c;
@ -216,7 +234,7 @@ int main(int argc, char *argv[]) {
return 0; return 0;
break; break;
case 'n': case 'n':
pass = strtol(optarg, NULL, 10); pass = parselong(optarg);
break; break;
case 'S': case 'S':
Sflag = 1; Sflag = 1;

View File

@ -28,11 +28,11 @@
#define _XOPEN_SOURCE #define _XOPEN_SOURCE
#include <ctype.h> #include <ctype.h> // isprint
#include <libgen.h> #include <libgen.h> // basename
#include <stdio.h> #include <stdio.h> // fprintf, printf
#include <stdlib.h> #include <stdlib.h> // exit
#include <unistd.h> #include <unistd.h> // getopt, unlink
static const char *__progname; static const char *__progname;
int vflag; int vflag;

View File

@ -26,7 +26,7 @@
* *
*/ */
#include <stdio.h> #include <stdio.h> // puts
int main(int argc, char * argv[]) { int main(int argc, char * argv[]) {
char * y; char * y;