From 6dd66df5946fd7809cde3241dbc6a40ec7931a70 Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Wed, 11 Jan 2012 15:52:41 -0600 Subject: [PATCH] Make master build on Windows Add strtoll()/strtoull() to lib/roken Add stdint.h to lib/roken (Windows only) Add logic to detect whether to use lib/roken's stdint.h based on Visual Studio version Add include of stdint.h in generated ASN.1 code Export missing symbols for 64-bit integers in lib/asn1 Export missing symbols for FAST Add missing sources to kdc/NTMakefile Fix issue in kuserok Fix bsearch issues --- base/NTMakefile | 1 + base/bsearch.c | 14 +- cf/roken-frag.m4 | 10 ++ include/NTMakefile | 2 + kdc/NTMakefile | 3 + lib/asn1/Makefile.am | 2 + lib/asn1/NTMakefile | 2 +- lib/asn1/der.h | 2 + lib/asn1/gen.c | 2 + lib/asn1/heim_asn1.h | 2 + lib/asn1/libasn1-exports.def | 16 ++ lib/asn1/{heim_asn1.h => roken_rename.h} | 28 ++- lib/asn1/symbol.h | 1 + lib/krb5/kuserok.c | 2 +- lib/krb5/libkrb5-exports.def.in | 13 ++ lib/roken/Makefile.am | 1 - lib/roken/NTMakefile | 6 + lib/roken/roken.h.in | 16 ++ lib/roken/stdint.hin | 15 ++ lib/roken/strtoll.c | 300 +++++++++++++++---------------- lib/roken/strtoull.c | 127 +++++++++++++ lib/roken/version-script.map | 2 + windows/NTMakefile.config | 8 + 23 files changed, 402 insertions(+), 173 deletions(-) copy lib/asn1/{heim_asn1.h => roken_rename.h} (66%) create mode 100644 lib/roken/stdint.hin rewrite lib/roken/strtoll.c (67%) create mode 100644 lib/roken/strtoull.c diff --git a/base/NTMakefile b/base/NTMakefile index c95dff8d9..6a389d50d 100644 --- a/base/NTMakefile +++ b/base/NTMakefile @@ -37,6 +37,7 @@ INCFILES=$(INCDIR)\heimbase.h libheimbase_OBJS = \ $(OBJ)\array.obj \ + $(OBJ)\bsearch.obj \ $(OBJ)\bool.obj \ $(OBJ)\dict.obj \ $(OBJ)\error.obj \ diff --git a/base/bsearch.c b/base/bsearch.c index 9fbd9026d..513d57f1e 100644 --- a/base/bsearch.c +++ b/base/bsearch.c @@ -33,16 +33,19 @@ #include #include +#ifdef HAVE_UNISTD_H #include +#endif #include #include #include #include #include +#ifdef HAVE_STRINGS_H #include +#endif #include #include -#include /* * This file contains functions for binary searching flat text in memory @@ -267,9 +270,12 @@ bsearch_common(const char *buf, size_t sz, const char *key, *location = key_start; ret = 0; if (val_len && value) { - *value = strndup(&buf[val_start], val_len); + /* Avoid strndup() so we don't need libroken here yet */ + *value = malloc(val_len + 1); if (!*value) ret = errno; + (void) memcpy(*value, &buf[val_start], val_len); + (*value)[val_len] = '\0'; } break; } @@ -376,7 +382,11 @@ __bsearch_file_open(const char *fname, size_t max_sz, size_t page_sz, } } if (page_sz == 0) +#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE page_sz = st.st_blksize; +#else + page_sz = 4096; +#endif for (i = page_sz; i; i >>= 1) { /* Make sure page_sz is a power of two */ if ((i % 2) && (i >> 1)) { diff --git a/cf/roken-frag.m4 b/cf/roken-frag.m4 index 5efecd51a..7e9f8da11 100644 --- a/cf/roken-frag.m4 +++ b/cf/roken-frag.m4 @@ -370,6 +370,8 @@ AC_BROKEN([ \ strsep \ strsep_copy \ strtok_r \ + strtoll \ + strtoull \ strupr \ swab \ tsearch \ @@ -391,6 +393,14 @@ AM_CONDITIONAL(have_fnmatch_h, AC_FOREACH([rk_func], [strndup strsep strtok_r], [AC_NEED_PROTO([#include ], rk_func)]) +AC_CHECK_FUNC([strtoll], + [AC_DEFINE_UNQUOTED(HAVE_STRTOLL, 1, + [Define if you have the function strtoll.])]) + +AC_CHECK_FUNC([strtoull], + [AC_DEFINE_UNQUOTED(HAVE_STRTOULL, 1, + [Define if you have the function strtoull.])]) + AC_FOREACH([rk_func], [strsvis strsvisx strunvis strvis strvisx svis unvis vis], [AC_NEED_PROTO([#ifdef HAVE_VIS_H #include diff --git a/include/NTMakefile b/include/NTMakefile index f3749fa4e..0086ee31a 100644 --- a/include/NTMakefile +++ b/include/NTMakefile @@ -75,6 +75,8 @@ while(<>) { if ("$(ENV_HACK)") { print "#define ENV_HACK 1\n"; } if ("$(HAVE_KCM)") { print "#define HAVE_KCM 1\n"; } if ("$(HAVE_SCC)") { print "#define HAVE_SCC 1\n"; } + if ("$(HAVE_STDINT_H)") { print "#define HAVE_STDINT_H 1\n"; } + if ("$(HAVE_INT64_T)") { print "#define HAVE_INT64_T 1\n"; } if ("$(DIR_hdbdir)") { print "#define HDB_DB_DIR \"".'$(DIR_hdbdir)'."\"\n"; } if ("$(HAVE_MSLSA_CACHE)") { print "#define HAVE_MSLSA_CACHE 1\n"; } if ("$(NO_LOCALNAME)") { print "#define NO_LOCALNAME 1\n"; } diff --git a/kdc/NTMakefile b/kdc/NTMakefile index 7b0dc8055..b7bebfecc 100644 --- a/kdc/NTMakefile +++ b/kdc/NTMakefile @@ -94,6 +94,7 @@ LIBKDC_OBJS=\ $(OBJ)\default_config.obj \ $(OBJ)\set_dbinfo.obj \ $(OBJ)\digest.obj \ + $(OBJ)\fast.obj \ $(OBJ)\kerberos5.obj \ $(OBJ)\krb5tgs.obj \ $(OBJ)\pkinit.obj \ @@ -105,6 +106,7 @@ LIBKDC_OBJS=\ LIBKDC_LIBS=\ $(LIBHDB) \ + $(LIBHEIMBASE) \ $(LIBHEIMDAL) \ $(LIBHEIMNTLM) \ $(LIBROKEN) @@ -124,6 +126,7 @@ libkdc_la_SOURCES = \ default_config.c \ set_dbinfo.c \ digest.c \ + fast.c \ kdc_locl.h \ kerberos5.c \ krb5tgs.c \ diff --git a/lib/asn1/Makefile.am b/lib/asn1/Makefile.am index 8e90c6690..14beffc0a 100644 --- a/lib/asn1/Makefile.am +++ b/lib/asn1/Makefile.am @@ -4,6 +4,8 @@ include $(top_srcdir)/Makefile.am.common YFLAGS = -d -t +AM_CPPFLAGS += $(ROKEN_RENAME) + lib_LTLIBRARIES = libasn1.la libasn1_la_LDFLAGS = -version-info 8:0:0 diff --git a/lib/asn1/NTMakefile b/lib/asn1/NTMakefile index 1ee62b198..6cd05f639 100644 --- a/lib/asn1/NTMakefile +++ b/lib/asn1/NTMakefile @@ -31,7 +31,7 @@ RELDIR=lib\asn1 -intcflags=-I$(SRCDIR) -I$(OBJ) +intcflags=-I$(SRCDIR) -I$(OBJ) -DROKEN_RENAME !include ../../windows/NTMakefile.w32 diff --git a/lib/asn1/der.h b/lib/asn1/der.h index f20cdb83c..f73234864 100644 --- a/lib/asn1/der.h +++ b/lib/asn1/der.h @@ -36,6 +36,8 @@ #ifndef __DER_H__ #define __DER_H__ +#include + typedef enum { ASN1_C_UNIV = 0, ASN1_C_APPL = 1, diff --git a/lib/asn1/gen.c b/lib/asn1/gen.c index a43903d19..ea459de17 100644 --- a/lib/asn1/gen.c +++ b/lib/asn1/gen.c @@ -264,6 +264,7 @@ init_generate (const char *filename, const char *base) "/* Do not edit */\n\n" "#include \n" "#include \n" + "#include \n" "#include \n" "#include \n" "#include \n" @@ -363,6 +364,7 @@ generate_header_of_codefile(const char *name) "#define ASN1_LIB\n\n" "#include \n" "#include \n" + "#include \n" "#include \n" "#include \n" "#include \n" diff --git a/lib/asn1/heim_asn1.h b/lib/asn1/heim_asn1.h index 4eeafc20f..23041251b 100644 --- a/lib/asn1/heim_asn1.h +++ b/lib/asn1/heim_asn1.h @@ -34,6 +34,8 @@ #ifndef __HEIM_ANY_H__ #define __HEIM_ANY_H__ 1 +#include + int encode_heim_any(unsigned char *, size_t, const heim_any *, size_t *); int decode_heim_any(const unsigned char *, size_t, heim_any *, size_t *); void free_heim_any(heim_any *); diff --git a/lib/asn1/libasn1-exports.def b/lib/asn1/libasn1-exports.def index 6dfb93ea0..413da55fa 100644 --- a/lib/asn1/libasn1-exports.def +++ b/lib/asn1/libasn1-exports.def @@ -299,6 +299,8 @@ EXPORTS copy_IssuerAndSerialNumber copy_KDCDHKeyInfo copy_KDCDHKeyInfo_Win2k + copy_KDCFastCookie + copy_KDCFastState copy_KDCOptions copy_KDC_REP copy_KDC_REQ @@ -551,6 +553,8 @@ EXPORTS decode_IssuerAndSerialNumber decode_KDCDHKeyInfo decode_KDCDHKeyInfo_Win2k + decode_KDCFastCookie + decode_KDCFastState decode_KDCOptions decode_KDC_REP decode_KDC_REQ @@ -699,6 +703,7 @@ EXPORTS der_copy_heim_integer der_copy_ia5_string der_copy_integer + der_copy_integer64 der_copy_octet_string der_copy_oid der_copy_printable_string @@ -714,6 +719,7 @@ EXPORTS der_free_heim_integer der_free_ia5_string der_free_integer + der_free_integer64 der_free_octet_string der_free_oid der_free_printable_string @@ -732,6 +738,7 @@ EXPORTS der_get_heim_integer der_get_ia5_string der_get_integer + der_get_integer64 der_get_length der_get_octet_string der_get_octet_string_ber @@ -763,6 +770,7 @@ EXPORTS der_length_heim_integer der_length_ia5_string der_length_integer + der_length_integer64 der_length_len der_length_octet_string der_length_oid @@ -789,6 +797,8 @@ EXPORTS der_put_heim_integer der_put_ia5_string der_put_integer + der_put_integer64 + der_put_integer64 der_put_length der_put_length_and_tag der_put_octet_string @@ -911,6 +921,8 @@ EXPORTS encode_IssuerAndSerialNumber encode_KDCDHKeyInfo encode_KDCDHKeyInfo_Win2k + encode_KDCFastCookie + encode_KDCFastState encode_KDCOptions encode_KDC_REP encode_KDC_REQ @@ -1163,6 +1175,8 @@ EXPORTS free_IssuerAndSerialNumber free_KDCDHKeyInfo free_KDCDHKeyInfo_Win2k + free_KDCFastCookie + free_KDCFastState free_KDCOptions free_KDC_REP free_KDC_REQ @@ -1426,6 +1440,8 @@ EXPORTS length_IssuerAndSerialNumber length_KDCDHKeyInfo length_KDCDHKeyInfo_Win2k + length_KDCFastCookie + length_KDCFastState length_KDCOptions length_KDC_REP length_KDC_REQ diff --git a/lib/asn1/heim_asn1.h b/lib/asn1/roken_rename.h similarity index 66% copy from lib/asn1/heim_asn1.h copy to lib/asn1/roken_rename.h index 4eeafc20f..76e108a55 100644 --- a/lib/asn1/heim_asn1.h +++ b/lib/asn1/roken_rename.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2005 Kungliga Tekniska Högskolan + * Copyright (c) 1998 Kungliga Tekniska Högskolan * (Royal Institute of Technology, Stockholm, Sweden). * All rights reserved. * @@ -31,22 +31,16 @@ * SUCH DAMAGE. */ -#ifndef __HEIM_ANY_H__ -#define __HEIM_ANY_H__ 1 +/* $Id$ */ -int encode_heim_any(unsigned char *, size_t, const heim_any *, size_t *); -int decode_heim_any(const unsigned char *, size_t, heim_any *, size_t *); -void free_heim_any(heim_any *); -size_t length_heim_any(const heim_any *); -int copy_heim_any(const heim_any *, heim_any *); +#ifndef __roken_rename_h__ +#define __roken_rename_h__ -int encode_heim_any_set(unsigned char *, size_t, - const heim_any_set *, size_t *); -int decode_heim_any_set(const unsigned char *, size_t, - heim_any_set *,size_t *); -void free_heim_any_set(heim_any_set *); -size_t length_heim_any_set(const heim_any_set *); -int copy_heim_any_set(const heim_any_set *, heim_any_set *); -int heim_any_cmp(const heim_any_set *, const heim_any_set *); +#ifndef HAVE_STRTOLL +#define strtoll rk_strtoll +#endif +#ifndef HAVE_STRTOULL +#define strtoull rk_strtoull +#endif -#endif /* __HEIM_ANY_H__ */ +#endif /* __roken_rename_h__ */ diff --git a/lib/asn1/symbol.h b/lib/asn1/symbol.h index 3a2d91bc9..a00331617 100644 --- a/lib/asn1/symbol.h +++ b/lib/asn1/symbol.h @@ -37,6 +37,7 @@ #define _SYMBOL_H #include "asn1_queue.h" +#include enum typetype { TBitString, diff --git a/lib/krb5/kuserok.c b/lib/krb5/kuserok.c index 469e3c786..c6f887102 100644 --- a/lib/krb5/kuserok.c +++ b/lib/krb5/kuserok.c @@ -205,7 +205,7 @@ check_owner_file(krb5_context context, * NFSv4 servers do?). Checking the owner means doing an LSARPC * lookup at least (to get the user's SID). */ - if (is_system_location || owner == NULL) + if (owner == NULL) return 0; krb5_set_error_message(context, EACCES, diff --git a/lib/krb5/libkrb5-exports.def.in b/lib/krb5/libkrb5-exports.def.in index ffa71f786..b32393385 100644 --- a/lib/krb5/libkrb5-exports.def.in +++ b/lib/krb5/libkrb5-exports.def.in @@ -760,6 +760,19 @@ EXPORTS krb5_get_init_creds_opt_set_pkinit_user_certs krb5_pk_enterprise_cert + krb5_auth_con_getsendsubkey + krb5_init_creds_free + krb5_init_creds_get + krb5_init_creds_get_creds + krb5_init_creds_get_error + krb5_init_creds_init + krb5_init_creds_set_fast_ccache + krb5_init_creds_set_keytab + krb5_init_creds_set_password + krb5_init_creds_set_service + krb5_init_creds_store + krb5_process_last_request + ; testing ;! _krb5_aes_cts_encrypt _krb5_n_fold diff --git a/lib/roken/Makefile.am b/lib/roken/Makefile.am index 04ec5d92c..2d4a90844 100644 --- a/lib/roken/Makefile.am +++ b/lib/roken/Makefile.am @@ -114,7 +114,6 @@ libroken_la_SOURCES = \ socket.c \ strcollect.c \ strerror_r.c \ - strtoll.c \ strpool.c \ timeval.c \ tm2time.c \ diff --git a/lib/roken/NTMakefile b/lib/roken/NTMakefile index fab0a0cc0..0bfa87f4e 100644 --- a/lib/roken/NTMakefile +++ b/lib/roken/NTMakefile @@ -99,6 +99,8 @@ libroken_la_OBJS = \ $(OBJ)\strsep.obj \ $(OBJ)\strsep_copy.obj \ $(OBJ)\strtok_r.obj \ + $(OBJ)\strtoll.obj \ + $(OBJ)\strtoull.obj \ $(OBJ)\syslogc.obj \ $(OBJ)\timegm.obj \ $(OBJ)\timeval.obj \ @@ -162,6 +164,10 @@ INCFILES = \ $(INCDIR)\vis.h \ $(INCDIR)\xdbm.h +#!ifndef HAVE_STDINT_H +#INCFILES += $(INCDIR)\stdint.h +#!endif + clean:: -$(RM) $(XHEADERS) diff --git a/lib/roken/roken.h.in b/lib/roken/roken.h.in index a101f66c2..210709b97 100644 --- a/lib/roken/roken.h.in +++ b/lib/roken/roken.h.in @@ -1033,6 +1033,22 @@ ROKEN_LIB_FUNCTION struct tm * ROKEN_LIB_CALL localtime_r(const time_t *, struct tm *); #endif +#if !defined(HAVE_STRTOLL) || defined(NEED_STRTOLL_PROTO) +#ifndef HAVE_STRTOLL +#define strtoll rk_strtoll +#endif +ROKEN_LIB_FUNCTION long long ROKEN_LIB_CALL +strtoll(const char * __restrict nptr, char ** __restrict endptr, int base); +#endif + +#if !defined(HAVE_STRTOULL) || defined(NEED_STRTOULL_PROTO) +#ifndef HAVE_STRTOULL +#define strtoull rk_strtoull +#endif +ROKEN_LIB_FUNCTION unsigned long long ROKEN_LIB_CALL +strtoull(const char * __restrict nptr, char ** __restrict endptr, int base); +#endif + #if !defined(HAVE_STRSVIS) || defined(NEED_STRSVIS_PROTO) #ifndef HAVE_STRSVIS #define strsvis rk_strsvis diff --git a/lib/roken/stdint.hin b/lib/roken/stdint.hin new file mode 100644 index 000000000..4a8387a4e --- /dev/null +++ b/lib/roken/stdint.hin @@ -0,0 +1,15 @@ +#ifndef _STDINT_H +#define _STDINT_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef long long int64_t; +typedef unsigned long long uint64_t; + +#ifdef __cplusplus +} +#endif + +#endif /* _STDINT_H */ diff --git a/lib/roken/strtoll.c b/lib/roken/strtoll.c dissimilarity index 67% index 5909ec571..89e1a77d3 100644 --- a/lib/roken/strtoll.c +++ b/lib/roken/strtoll.c @@ -1,151 +1,149 @@ -/*- - * Copyright (c) 1992, 1993 - * 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. - * 4. 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. - */ - -#if 1 -#include -#include "roken.h" -#include - -#else -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strtoq.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD$"); -#endif - -#include -#include -#include -#include - -ROKEN_LIB_FUNCTION long long ROKEN_LIB_CALL -rk_strtoll(const char * __restrict nptr, char ** __restrict endptr, int base); - -/* - * Convert a string to a long long integer. - * - * Assumes that the upper and lower case - * alphabets and digits are each contiguous. - */ - -ROKEN_LIB_FUNCTION long long ROKEN_LIB_CALL -rk_strtoll(const char * __restrict nptr, char ** __restrict endptr, int base) -{ - const char *s; - unsigned long long acc; - char c; - unsigned long long cutoff; - int neg, any, cutlim; - - /* - * Skip white space and pick up leading +/- sign if any. - * If base is 0, allow 0x for hex and 0 for octal, else - * assume decimal; if base is already 16, allow 0x. - */ - s = nptr; - do { - c = *s++; - } while (isspace((unsigned char)c)); - if (c == '-') { - neg = 1; - c = *s++; - } else { - neg = 0; - if (c == '+') - c = *s++; - } - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X') && - ((s[1] >= '0' && s[1] <= '9') || - (s[1] >= 'A' && s[1] <= 'F') || - (s[1] >= 'a' && s[1] <= 'f'))) { - c = s[1]; - s += 2; - base = 16; - } - if (base == 0) - base = c == '0' ? 8 : 10; - acc = any = 0; - if (base < 2 || base > 36) - goto noconv; - - /* - * Compute the cutoff value between legal numbers and illegal - * numbers. That is the largest legal value, divided by the - * base. An input number that is greater than this value, if - * followed by a legal input character, is too big. One that - * is equal to this value may be valid or not; the limit - * between valid and invalid numbers is then based on the last - * digit. For instance, if the range for quads is - * [-9223372036854775808..9223372036854775807] and the input base - * is 10, cutoff will be set to 922337203685477580 and cutlim to - * either 7 (neg==0) or 8 (neg==1), meaning that if we have - * accumulated a value > 922337203685477580, or equal but the - * next digit is > 7 (or 8), the number is too big, and we will - * return a range error. - * - * Set 'any' if any `digits' consumed; make it negative to indicate - * overflow. - */ - cutoff = neg ? (unsigned long long)-(LLONG_MIN + LLONG_MAX) + LLONG_MAX - : LLONG_MAX; - cutlim = cutoff % base; - cutoff /= base; - for ( ; ; c = *s++) { - if (c >= '0' && c <= '9') - c -= '0'; - else if (c >= 'A' && c <= 'Z') - c -= 'A' - 10; - else if (c >= 'a' && c <= 'z') - c -= 'a' - 10; - else - break; - if (c >= base) - break; - if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) - any = -1; - else { - any = 1; - acc *= base; - acc += c; - } - } - if (any < 0) { - acc = neg ? LLONG_MIN : LLONG_MAX; - errno = ERANGE; - } else if (!any) { -noconv: - errno = EINVAL; - } else if (neg) - acc = -acc; - if (endptr != NULL) - *endptr = (char *)(any ? s - 1 : nptr); - return (acc); -} +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Copyright (c) 2011 The FreeBSD Foundation + * All rights reserved. + * Portions of this software were developed by David Chisnall + * under sponsorship from the FreeBSD Foundation. + * + * 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. + * 4. 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 + +#include + +#include "roken.h" + +/* #include */ + +#include +#include +#include +#include +#include + +/* + * Convert a string to a long long integer. + * + * Assumes that the upper and lower case + * alphabets and digits are each contiguous. + */ +ROKEN_LIB_FUNCTION long long ROKEN_LIB_CALL +strtoll(const char * __restrict nptr, char ** __restrict endptr, int base) +{ + const char *s; + unsigned long long acc; + char c; + unsigned long long cutoff; + int neg, any, cutlim; + + /* + * Skip white space and pick up leading +/- sign if any. + * If base is 0, allow 0x for hex and 0 for octal, else + * assume decimal; if base is already 16, allow 0x. + */ + s = nptr; + do { + c = *s++; + } while (isspace((unsigned char)c)); + if (c == '-') { + neg = 1; + c = *s++; + } else { + neg = 0; + if (c == '+') + c = *s++; + } + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X') && + ((s[1] >= '0' && s[1] <= '9') || + (s[1] >= 'A' && s[1] <= 'F') || + (s[1] >= 'a' && s[1] <= 'f'))) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == '0' ? 8 : 10; + acc = any = 0; + if (base < 2 || base > 36) + goto noconv; + + /* + * Compute the cutoff value between legal numbers and illegal + * numbers. That is the largest legal value, divided by the + * base. An input number that is greater than this value, if + * followed by a legal input character, is too big. One that + * is equal to this value may be valid or not; the limit + * between valid and invalid numbers is then based on the last + * digit. For instance, if the range for quads is + * [-9223372036854775808..9223372036854775807] and the input base + * is 10, cutoff will be set to 922337203685477580 and cutlim to + * either 7 (neg==0) or 8 (neg==1), meaning that if we have + * accumulated a value > 922337203685477580, or equal but the + * next digit is > 7 (or 8), the number is too big, and we will + * return a range error. + * + * Set 'any' if any `digits' consumed; make it negative to indicate + * overflow. + */ + cutoff = neg ? (unsigned long long)-(LLONG_MIN + LLONG_MAX) + LLONG_MAX + : LLONG_MAX; + cutlim = cutoff % base; + cutoff /= base; + for ( ; ; c = *s++) { + if (c >= '0' && c <= '9') + c -= '0'; + else if (c >= 'A' && c <= 'Z') + c -= 'A' - 10; + else if (c >= 'a' && c <= 'z') + c -= 'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) { + acc = neg ? LLONG_MIN : LLONG_MAX; + errno = ERANGE; + } else if (!any) { +noconv: + errno = EINVAL; + } else if (neg) + acc = -acc; + if (endptr != NULL) + *endptr = (char *)(any ? s - 1 : nptr); + return (acc); +} + diff --git a/lib/roken/strtoull.c b/lib/roken/strtoull.c new file mode 100644 index 000000000..b954a0706 --- /dev/null +++ b/lib/roken/strtoull.c @@ -0,0 +1,127 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Copyright (c) 2011 The FreeBSD Foundation + * All rights reserved. + * Portions of this software were developed by David Chisnall + * under sponsorship from the FreeBSD Foundation. + * + * 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. + * 4. 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 + +#include + +#include "roken.h" + +/* #include */ + +#include +#include +#include +#include +#include + +/* + * Convert a string to an unsigned long long integer. + * + * Assumes that the upper and lower case + * alphabets and digits are each contiguous. + */ +ROKEN_LIB_FUNCTION unsigned long long ROKEN_LIB_CALL +strtoull(const char * __restrict nptr, char ** __restrict endptr, int base) +{ + const char *s; + unsigned long long acc; + char c; + unsigned long long cutoff; + int neg, any, cutlim; + + /* + * See strtoq for comments as to the logic used. + */ + s = nptr; + do { + c = *s++; + } while (isspace((unsigned char)c)); + if (c == '-') { + neg = 1; + c = *s++; + } else { + neg = 0; + if (c == '+') + c = *s++; + } + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X') && + ((s[1] >= '0' && s[1] <= '9') || + (s[1] >= 'A' && s[1] <= 'F') || + (s[1] >= 'a' && s[1] <= 'f'))) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == '0' ? 8 : 10; + acc = any = 0; + if (base < 2 || base > 36) + goto noconv; + + cutoff = ULLONG_MAX / base; + cutlim = ULLONG_MAX % base; + for ( ; ; c = *s++) { + if (c >= '0' && c <= '9') + c -= '0'; + else if (c >= 'A' && c <= 'Z') + c -= 'A' - 10; + else if (c >= 'a' && c <= 'z') + c -= 'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) { + acc = ULLONG_MAX; + errno = ERANGE; + } else if (!any) { +noconv: + errno = EINVAL; + } else if (neg) + acc = -acc; + if (endptr != NULL) + *endptr = (char *)(any ? s - 1 : nptr); + return (acc); +} + diff --git a/lib/roken/version-script.map b/lib/roken/version-script.map index 9229a373c..e11bafa04 100644 --- a/lib/roken/version-script.map +++ b/lib/roken/version-script.map @@ -125,6 +125,8 @@ HEIMDAL_ROKEN_1.0 { rk_strsvis; rk_strsvis; rk_strsvisx; + rk_strtoll; + rk_strtoull; rk_strunvis; rk_strunvis; rk_strunvisx; diff --git a/windows/NTMakefile.config b/windows/NTMakefile.config index 3d6fe7abd..6fcf1fc56 100644 --- a/windows/NTMakefile.config +++ b/windows/NTMakefile.config @@ -8,6 +8,14 @@ ! include !endif +!if [ $(PERL) $(SRC)\cf\w32-detect-vc-version.pl $(CC) ]==16 +HAVE_STDINT_H=1 +HAVE_INT64_T=1 +!endif + + + + # ------------------------------------------------------------ # Features # -- 2.11.4.GIT