feat: add compatibility with linux
Signed-off-by: sisungo <[email protected]>
This commit is contained in:
+3
-3
@@ -1,9 +1,9 @@
|
|||||||
/*-
|
/*-
|
||||||
* Copyright (C) 1990 Free Software Foundation, Inc.
|
* Copyright (C) 1990 Free Software Foundation, Inc.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
* without restriction.
|
* without restriction.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
@@ -104,7 +104,7 @@ max_backup_version(const char *file, const char *dir)
|
|||||||
file_name_length = strlen(file);
|
file_name_length = strlen(file);
|
||||||
|
|
||||||
while ((dp = readdir(dirp)) != NULL) {
|
while ((dp = readdir(dirp)) != NULL) {
|
||||||
if (dp->d_namlen <= file_name_length)
|
if (strlen(dp->d_name) <= file_name_length)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
this_version = version_number(file, dp->d_name, file_name_length);
|
this_version = version_number(file, dp->d_name, file_name_length);
|
||||||
|
|||||||
@@ -1,9 +1,87 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
static inline void *reallocarray(void *p, size_t n, size_t size) {
|
static inline long long strtonum(const char *nptr, long long minval,
|
||||||
if (n && size > (size_t)-1 / n) {
|
long long maxval, const char **errstr) {
|
||||||
errno = ENOMEM;
|
const char *p = nptr;
|
||||||
return NULL;
|
char *endptr;
|
||||||
|
long long result;
|
||||||
|
int saved_errno;
|
||||||
|
|
||||||
|
if (errstr != NULL)
|
||||||
|
*errstr = NULL;
|
||||||
|
|
||||||
|
if (nptr == NULL || *nptr == '\0') {
|
||||||
|
if (errstr != NULL)
|
||||||
|
*errstr = "invalid";
|
||||||
|
errno = EINVAL;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
return realloc(p, n * size);
|
|
||||||
|
if (minval > maxval) {
|
||||||
|
if (errstr != NULL)
|
||||||
|
*errstr = "invalid";
|
||||||
|
errno = EINVAL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (isspace((unsigned char)*p))
|
||||||
|
p++;
|
||||||
|
|
||||||
|
saved_errno = errno;
|
||||||
|
errno = 0;
|
||||||
|
|
||||||
|
result = strtoll(p, &endptr, 10);
|
||||||
|
|
||||||
|
if (errno == ERANGE) {
|
||||||
|
if (errstr != NULL) {
|
||||||
|
*errstr = (result == LLONG_MIN || result < minval) ?
|
||||||
|
"too small" : "too large";
|
||||||
|
}
|
||||||
|
errno = ERANGE;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (endptr == p) {
|
||||||
|
if (errstr != NULL)
|
||||||
|
*errstr = "invalid";
|
||||||
|
errno = EINVAL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (isspace((unsigned char)*endptr))
|
||||||
|
endptr++;
|
||||||
|
if (*endptr != '\0') {
|
||||||
|
if (errstr != NULL)
|
||||||
|
*errstr = "invalid";
|
||||||
|
errno = EINVAL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result < minval) {
|
||||||
|
if (errstr != NULL)
|
||||||
|
*errstr = "too small";
|
||||||
|
errno = ERANGE;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (result > maxval) {
|
||||||
|
if (errstr != NULL)
|
||||||
|
*errstr = "too large";
|
||||||
|
errno = ERANGE;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errstr != NULL)
|
||||||
|
*errstr = NULL;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void *reallocf(void *ptr, size_t size) {
|
||||||
|
void *new_ptr = realloc(ptr, size);
|
||||||
|
if (new_ptr == NULL && size != 0) {
|
||||||
|
free(ptr);
|
||||||
|
}
|
||||||
|
return new_ptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
/*-
|
/*-
|
||||||
* Copyright 1986, Larry Wall
|
* Copyright 1986, Larry Wall
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following condition is met:
|
* modification, are permitted provided that the following condition is met:
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
* this condition and the following disclaimer.
|
* this condition and the following disclaimer.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
|
||||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
* 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
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* patch - a program to apply diffs to original files
|
* patch - a program to apply diffs to original files
|
||||||
*
|
*
|
||||||
* -C option added in 1998, original code by Marc Espie, based on FreeBSD
|
* -C option added in 1998, original code by Marc Espie, based on FreeBSD
|
||||||
@@ -43,12 +43,12 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "inp.h"
|
#include "inp.h"
|
||||||
#include "compat.h"
|
|
||||||
|
|
||||||
/* Input-file-with-indexable-lines abstract type */
|
/* Input-file-with-indexable-lines abstract type */
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
/*-
|
/*-
|
||||||
* Copyright 1986, Larry Wall
|
* Copyright 1986, Larry Wall
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following condition is met:
|
* modification, are permitted provided that the following condition is met:
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
* this condition and the following disclaimer.
|
* this condition and the following disclaimer.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
|
||||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
* 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
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* patch - a program to apply diffs to original files
|
* patch - a program to apply diffs to original files
|
||||||
*
|
*
|
||||||
* -C option added in 1998, original code by Marc Espie, based on FreeBSD
|
* -C option added in 1998, original code by Marc Espie, based on FreeBSD
|
||||||
@@ -42,6 +42,7 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "pathnames.h"
|
#include "pathnames.h"
|
||||||
|
#include "compat.h"
|
||||||
|
|
||||||
/* Patch (diff listing) abstract type. */
|
/* Patch (diff listing) abstract type. */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user