mirror of
https://github.com/openbsd/src.git
synced 2025-01-04 15:25:38 -08:00
Support 64 bit integers on 32 bit architectures.
No binary change on amd64 and there should be no differences on any other 64 bit architecture either (because long = int64_t). ok cheloha, tb
This commit is contained in:
parent
7f24418351
commit
517d388001
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: c_ksh.c,v 1.59 2018/03/15 16:51:29 anton Exp $ */
|
||||
/* $OpenBSD: c_ksh.c,v 1.60 2018/04/09 17:53:36 tobias Exp $ */
|
||||
|
||||
/*
|
||||
* built-in Korn commands: c_*
|
||||
@ -1017,7 +1017,7 @@ int
|
||||
c_let(char **wp)
|
||||
{
|
||||
int rv = 1;
|
||||
long val;
|
||||
int64_t val;
|
||||
|
||||
if (wp[1] == NULL) /* at&t ksh does this */
|
||||
bi_errorf("no arguments");
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: c_sh.c,v 1.62 2017/12/27 13:02:57 millert Exp $ */
|
||||
/* $OpenBSD: c_sh.c,v 1.63 2018/04/09 17:53:36 tobias Exp $ */
|
||||
|
||||
/*
|
||||
* built-in Bourne commands
|
||||
@ -33,7 +33,7 @@ c_shift(char **wp)
|
||||
{
|
||||
struct block *l = genv->loc;
|
||||
int n;
|
||||
long val;
|
||||
int64_t val;
|
||||
char *arg;
|
||||
|
||||
if (ksh_getopt(wp, &builtin_opt, null) == '?')
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: c_test.c,v 1.24 2017/12/26 19:10:31 millert Exp $ */
|
||||
/* $OpenBSD: c_test.c,v 1.25 2018/04/09 17:53:36 tobias Exp $ */
|
||||
|
||||
/*
|
||||
* test(1); version 7-like -- author Erik Baalbergen
|
||||
@ -308,7 +308,7 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2,
|
||||
case TO_INTLE: /* -le */
|
||||
case TO_INTLT: /* -lt */
|
||||
{
|
||||
long v1, v2;
|
||||
int64_t v1, v2;
|
||||
|
||||
if (!evaluate(opnd1, &v1, KSH_RETURN_ERROR, false) ||
|
||||
!evaluate(opnd2, &v2, KSH_RETURN_ERROR, false)) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: c_ulimit.c,v 1.27 2018/03/15 16:51:29 anton Exp $ */
|
||||
/* $OpenBSD: c_ulimit.c,v 1.28 2018/04/09 17:53:36 tobias Exp $ */
|
||||
|
||||
/*
|
||||
ulimit -- handle "ulimit" builtin
|
||||
@ -22,6 +22,7 @@
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "sh.h"
|
||||
@ -139,7 +140,7 @@ set_ulimit(const struct limits *l, const char *v, int how)
|
||||
if (strcmp(v, "unlimited") == 0)
|
||||
val = RLIM_INFINITY;
|
||||
else {
|
||||
long rval;
|
||||
int64_t rval;
|
||||
|
||||
if (!evaluate(v, &rval, KSH_RETURN_ERROR, false))
|
||||
return 1;
|
||||
@ -187,6 +188,6 @@ print_ulimit(const struct limits *l, int how)
|
||||
shprintf("unlimited\n");
|
||||
else {
|
||||
val /= l->factor;
|
||||
shprintf("%ld\n", (long) val);
|
||||
shprintf("%" PRIi64 "\n", (int64_t) val);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: edit.c,v 1.64 2018/03/15 16:51:29 anton Exp $ */
|
||||
/* $OpenBSD: edit.c,v 1.65 2018/04/09 17:53:36 tobias Exp $ */
|
||||
|
||||
/*
|
||||
* Command line editing - common code
|
||||
@ -80,10 +80,10 @@ check_sigwinch(void)
|
||||
ws.ws_col;
|
||||
|
||||
if ((vp = typeset("COLUMNS", 0, 0, 0, 0)))
|
||||
setint(vp, (long) ws.ws_col);
|
||||
setint(vp, (int64_t) ws.ws_col);
|
||||
}
|
||||
if (ws.ws_row && (vp = typeset("LINES", 0, 0, 0, 0)))
|
||||
setint(vp, (long) ws.ws_row);
|
||||
setint(vp, (int64_t) ws.ws_row);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: eval.c,v 1.59 2018/01/16 22:52:32 jca Exp $ */
|
||||
/* $OpenBSD: eval.c,v 1.60 2018/04/09 17:53:36 tobias Exp $ */
|
||||
|
||||
/*
|
||||
* Expansion - quoting, separation, substitution, globbing
|
||||
@ -732,7 +732,7 @@ varsub(Expand *xp, char *sp, char *word,
|
||||
if (Flag(FNOUNSET) && c == 0 && !zero_ok)
|
||||
errorf("%s: parameter not set", sp);
|
||||
*stypep = 0; /* unqualified variable/string substitution */
|
||||
xp->str = str_save(ulton((unsigned long)c, 10), ATEMP);
|
||||
xp->str = str_save(u64ton((uint64_t)c, 10), ATEMP);
|
||||
return XSUB;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: expr.c,v 1.32 2015/12/30 09:07:00 tedu Exp $ */
|
||||
/* $OpenBSD: expr.c,v 1.33 2018/04/09 17:53:36 tobias Exp $ */
|
||||
|
||||
/*
|
||||
* Korn expression evaluation
|
||||
@ -148,7 +148,7 @@ static struct tbl *intvar(Expr_state *, struct tbl *);
|
||||
* parse and evaluate expression
|
||||
*/
|
||||
int
|
||||
evaluate(const char *expr, long int *rval, int error_ok, bool arith)
|
||||
evaluate(const char *expr, int64_t *rval, int error_ok, bool arith)
|
||||
{
|
||||
struct tbl v;
|
||||
int ret;
|
||||
@ -280,7 +280,7 @@ evalexpr(Expr_state *es, enum prec prec)
|
||||
{
|
||||
struct tbl *vl, *vr = NULL, *vasn;
|
||||
enum token op;
|
||||
long res = 0;
|
||||
int64_t res = 0;
|
||||
|
||||
if (prec == P_PRIMARY) {
|
||||
op = es->tok;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: mail.c,v 1.22 2015/10/19 14:42:16 mmcc Exp $ */
|
||||
/* $OpenBSD: mail.c,v 1.23 2018/04/09 17:53:36 tobias Exp $ */
|
||||
|
||||
/*
|
||||
* Mailbox checking code by Robert J. Gibson, adapted for PD ksh by
|
||||
@ -81,7 +81,7 @@ mcheck(void)
|
||||
}
|
||||
|
||||
void
|
||||
mcset(long int interval)
|
||||
mcset(int64_t interval)
|
||||
{
|
||||
mailcheck_interval = interval;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: main.c,v 1.90 2018/03/15 16:51:29 anton Exp $ */
|
||||
/* $OpenBSD: main.c,v 1.91 2018/04/09 17:53:36 tobias Exp $ */
|
||||
|
||||
/*
|
||||
* startup, main loop, environments and error handling
|
||||
@ -287,7 +287,7 @@ main(int argc, char *argv[])
|
||||
setstr(pwd_v, current_wd, KSH_RETURN_ERROR);
|
||||
}
|
||||
ppid = getppid();
|
||||
setint(global("PPID"), (long) ppid);
|
||||
setint(global("PPID"), (int64_t) ppid);
|
||||
/* setstr can't fail here */
|
||||
setstr(global(version_param), ksh_version, KSH_RETURN_ERROR);
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: misc.c,v 1.69 2018/03/15 16:51:29 anton Exp $ */
|
||||
/* $OpenBSD: misc.c,v 1.70 2018/04/09 17:53:36 tobias Exp $ */
|
||||
|
||||
/*
|
||||
* Miscellaneous functions
|
||||
@ -56,10 +56,10 @@ initctypes(void)
|
||||
setctypes(" \n\t\"#$&'()*;<>?[\\`|", C_QUOTE);
|
||||
}
|
||||
|
||||
/* convert unsigned long to base N string */
|
||||
/* convert uint64_t to base N string */
|
||||
|
||||
char *
|
||||
ulton(long unsigned int n, int base)
|
||||
u64ton(uint64_t n, int base)
|
||||
{
|
||||
char *p;
|
||||
static char buf [20];
|
||||
|
14
bin/ksh/sh.h
14
bin/ksh/sh.h
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: sh.h,v 1.71 2018/01/16 22:52:32 jca Exp $ */
|
||||
/* $OpenBSD: sh.h,v 1.72 2018/04/09 17:53:36 tobias Exp $ */
|
||||
|
||||
/*
|
||||
* Public Domain Bourne/Korn shell
|
||||
@ -440,7 +440,7 @@ int search_access(const char *, int, int *);
|
||||
int pr_menu(char *const *);
|
||||
int pr_list(char *const *);
|
||||
/* expr.c */
|
||||
int evaluate(const char *, long *, int, bool);
|
||||
int evaluate(const char *, int64_t *, int, bool);
|
||||
int v_evaluate(struct tbl *, const char *, volatile int, bool);
|
||||
/* history.c */
|
||||
void init_histvec(void);
|
||||
@ -512,7 +512,7 @@ pid_t j_async(void);
|
||||
int j_stopped_running(void);
|
||||
/* mail.c */
|
||||
void mcheck(void);
|
||||
void mcset(long);
|
||||
void mcset(int64_t);
|
||||
void mbset(char *);
|
||||
void mpset(char *);
|
||||
/* main.c */
|
||||
@ -527,7 +527,7 @@ void cleanup_proc_env(void);
|
||||
/* misc.c */
|
||||
void setctypes(const char *, int);
|
||||
void initctypes(void);
|
||||
char * ulton(unsigned long, int);
|
||||
char * u64ton(uint64_t, int);
|
||||
char * str_save(const char *, Area *);
|
||||
char * str_nsave(const char *, int, Area *);
|
||||
int option(const char *);
|
||||
@ -583,11 +583,11 @@ void initvar(void);
|
||||
struct tbl * global(const char *);
|
||||
struct tbl * local(const char *, bool);
|
||||
char * str_val(struct tbl *);
|
||||
long intval(struct tbl *);
|
||||
int64_t intval(struct tbl *);
|
||||
int setstr(struct tbl *, const char *, int);
|
||||
struct tbl *setint_v(struct tbl *, struct tbl *, bool);
|
||||
void setint(struct tbl *, long);
|
||||
int getint(struct tbl *, long *, bool);
|
||||
void setint(struct tbl *, int64_t);
|
||||
int getint(struct tbl *, int64_t *, bool);
|
||||
struct tbl *typeset(const char *, int, int, int, int);
|
||||
void unset(struct tbl *, int);
|
||||
char * skip_varname(const char *, int);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: table.h,v 1.13 2017/12/27 13:02:57 millert Exp $ */
|
||||
/* $OpenBSD: table.h,v 1.14 2018/04/09 17:53:36 tobias Exp $ */
|
||||
|
||||
/* $From: table.h,v 1.3 1994/05/31 13:34:34 michael Exp $ */
|
||||
|
||||
@ -19,7 +19,7 @@ struct tbl { /* table item */
|
||||
Area *areap; /* area to allocate from */
|
||||
union {
|
||||
char *s; /* string */
|
||||
long i; /* integer */
|
||||
int64_t i; /* integer */
|
||||
int (*f)(char **); /* int function */
|
||||
struct op *t; /* "function" tree */
|
||||
} val; /* value */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: tree.c,v 1.33 2018/03/15 16:51:29 anton Exp $ */
|
||||
/* $OpenBSD: tree.c,v 1.34 2018/04/09 17:53:36 tobias Exp $ */
|
||||
|
||||
/*
|
||||
* command tree climbing
|
||||
@ -365,7 +365,7 @@ vfptreef(struct shf *shf, int indent, const char *fmt, va_list va)
|
||||
|
||||
while ((c = *fmt++)) {
|
||||
if (c == '%') {
|
||||
long n;
|
||||
int64_t n;
|
||||
char *p;
|
||||
int neg;
|
||||
|
||||
@ -376,7 +376,7 @@ vfptreef(struct shf *shf, int indent, const char *fmt, va_list va)
|
||||
case 'd': /* decimal */
|
||||
n = va_arg(va, int);
|
||||
neg = n < 0;
|
||||
p = ulton(neg ? -n : n, 10);
|
||||
p = u64ton(neg ? -n : n, 10);
|
||||
if (neg)
|
||||
*--p = '-';
|
||||
while (*p)
|
||||
@ -392,7 +392,7 @@ vfptreef(struct shf *shf, int indent, const char *fmt, va_list va)
|
||||
tputS(p, shf);
|
||||
break;
|
||||
case 'u': /* unsigned decimal */
|
||||
p = ulton(va_arg(va, unsigned int), 10);
|
||||
p = u64ton(va_arg(va, unsigned int), 10);
|
||||
while (*p)
|
||||
tputc(*p++, shf);
|
||||
break;
|
||||
|
@ -1,9 +1,10 @@
|
||||
/* $OpenBSD: var.c,v 1.66 2018/03/15 16:51:29 anton Exp $ */
|
||||
/* $OpenBSD: var.c,v 1.67 2018/04/09 17:53:36 tobias Exp $ */
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -136,7 +137,7 @@ array_index_calc(const char *n, bool *arrayp, int *valp)
|
||||
p = skip_varname(n, false);
|
||||
if (p != n && *p == '[' && (len = array_ref_len(p))) {
|
||||
char *sub, *tmp;
|
||||
long rval;
|
||||
int64_t rval;
|
||||
|
||||
/* Calculate the value of the subscript */
|
||||
*arrayp = true;
|
||||
@ -146,7 +147,8 @@ array_index_calc(const char *n, bool *arrayp, int *valp)
|
||||
n = str_nsave(n, p - n, ATEMP);
|
||||
evaluate(sub, &rval, KSH_UNWIND_ERROR, true);
|
||||
if (rval < 0 || rval > INT_MAX)
|
||||
errorf("%s: subscript %ld out of range", n, rval);
|
||||
errorf("%s: subscript %" PRIi64 " out of range",
|
||||
n, rval);
|
||||
*valp = rval;
|
||||
afree(sub, ATEMP);
|
||||
}
|
||||
@ -295,18 +297,18 @@ str_val(struct tbl *vp)
|
||||
else if (!(vp->flag&INTEGER)) /* string source */
|
||||
s = vp->val.s + vp->type;
|
||||
else { /* integer source */
|
||||
/* worst case number length is when base=2, so use BITS(long) */
|
||||
/* minus base # number null */
|
||||
char strbuf[1 + 2 + 1 + BITS(long) + 1];
|
||||
/* worst case number length is when base=2, so use
|
||||
* minus base # number BITS(int64_t) NUL */
|
||||
char strbuf[1 + 2 + 1 + BITS(int64_t) + 1];
|
||||
const char *digits = (vp->flag & UCASEV_AL) ?
|
||||
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" :
|
||||
"0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
unsigned long n;
|
||||
uint64_t n;
|
||||
unsigned int base;
|
||||
|
||||
s = strbuf + sizeof(strbuf);
|
||||
if (vp->flag & INT_U)
|
||||
n = (unsigned long) vp->val.i;
|
||||
n = (uint64_t) vp->val.i;
|
||||
else
|
||||
n = (vp->val.i < 0) ? -vp->val.i : vp->val.i;
|
||||
base = (vp->type == 0) ? 10 : vp->type;
|
||||
@ -335,10 +337,10 @@ str_val(struct tbl *vp)
|
||||
}
|
||||
|
||||
/* get variable integer value, with error checking */
|
||||
long
|
||||
int64_t
|
||||
intval(struct tbl *vp)
|
||||
{
|
||||
long num;
|
||||
int64_t num;
|
||||
int base;
|
||||
|
||||
base = getint(vp, &num, false);
|
||||
@ -393,7 +395,7 @@ setstr(struct tbl *vq, const char *s, int error_ok)
|
||||
|
||||
/* set variable to integer */
|
||||
void
|
||||
setint(struct tbl *vq, long int n)
|
||||
setint(struct tbl *vq, int64_t n)
|
||||
{
|
||||
if (!(vq->flag&INTEGER)) {
|
||||
struct tbl *vp = &vtemp;
|
||||
@ -411,13 +413,13 @@ setint(struct tbl *vq, long int n)
|
||||
}
|
||||
|
||||
int
|
||||
getint(struct tbl *vp, long int *nump, bool arith)
|
||||
getint(struct tbl *vp, int64_t *nump, bool arith)
|
||||
{
|
||||
char *s;
|
||||
int c;
|
||||
int base, neg;
|
||||
int have_base = 0;
|
||||
long num;
|
||||
int64_t num;
|
||||
|
||||
if (vp->flag&SPECIAL)
|
||||
getspec(vp);
|
||||
@ -483,7 +485,7 @@ struct tbl *
|
||||
setint_v(struct tbl *vq, struct tbl *vp, bool arith)
|
||||
{
|
||||
int base;
|
||||
long num;
|
||||
int64_t num;
|
||||
|
||||
if ((base = getint(vp, &num, arith)) == -1)
|
||||
return NULL;
|
||||
@ -920,27 +922,27 @@ getspec(struct tbl *vp)
|
||||
* (see initcoms[] in main.c).
|
||||
*/
|
||||
if (vp->flag & ISSET)
|
||||
setint(vp, (long)(time(NULL) - seconds)); /* XXX 2038 */
|
||||
setint(vp, (int64_t)(time(NULL) - seconds));
|
||||
vp->flag |= SPECIAL;
|
||||
break;
|
||||
case V_RANDOM:
|
||||
vp->flag &= ~SPECIAL;
|
||||
setint(vp, (long) (rand() & 0x7fff));
|
||||
setint(vp, (int64_t) (rand() & 0x7fff));
|
||||
vp->flag |= SPECIAL;
|
||||
break;
|
||||
case V_HISTSIZE:
|
||||
vp->flag &= ~SPECIAL;
|
||||
setint(vp, (long) histsize);
|
||||
setint(vp, (int64_t) histsize);
|
||||
vp->flag |= SPECIAL;
|
||||
break;
|
||||
case V_OPTIND:
|
||||
vp->flag &= ~SPECIAL;
|
||||
setint(vp, (long) user_opt.uoptind);
|
||||
setint(vp, (int64_t) user_opt.uoptind);
|
||||
vp->flag |= SPECIAL;
|
||||
break;
|
||||
case V_LINENO:
|
||||
vp->flag &= ~SPECIAL;
|
||||
setint(vp, (long) current_lineno + user_lineno);
|
||||
setint(vp, (int64_t) current_lineno + user_lineno);
|
||||
vp->flag |= SPECIAL;
|
||||
break;
|
||||
}
|
||||
@ -1004,7 +1006,7 @@ setspec(struct tbl *vp)
|
||||
break;
|
||||
case V_COLUMNS:
|
||||
{
|
||||
long l;
|
||||
int64_t l;
|
||||
|
||||
if (getint(vp, &l, false) == -1) {
|
||||
x_cols = MIN_COLS;
|
||||
@ -1034,7 +1036,7 @@ setspec(struct tbl *vp)
|
||||
break;
|
||||
case V_SECONDS:
|
||||
vp->flag &= ~SPECIAL;
|
||||
seconds = time(NULL) - intval(vp); /* XXX 2038 */
|
||||
seconds = time(NULL) - intval(vp);
|
||||
vp->flag |= SPECIAL;
|
||||
break;
|
||||
case V_TMOUT:
|
||||
|
@ -216,3 +216,14 @@ expected-stdout:
|
||||
64
|
||||
---
|
||||
|
||||
name: integer-1
|
||||
description:
|
||||
Check that 64 bit integers get assigned
|
||||
stdin:
|
||||
echo $(( zz = 0x7fffffffffffffff))
|
||||
echo $zz
|
||||
expected-stdout:
|
||||
9223372036854775807
|
||||
9223372036854775807
|
||||
---
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user