1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-06-30 19:12:48 -05:00

Adopt C99 <stdint.h> integer types.

The annoying int64.h is completely retired, since C99 guarantees a
64-bit integer type that you can actually treat like an ordinary
integer. Also, I've replaced the local typedefs uint32 and word32
(scattered through different parts of the crypto code) with the
standard uint32_t.
This commit is contained in:
Simon Tatham
2018-10-26 23:08:58 +01:00
parent 5cb56389bd
commit a647f2ba11
29 changed files with 432 additions and 721 deletions

View File

@ -20,7 +20,6 @@
#include "putty.h"
#include "ssh.h"
#include "psftp.h"
#include "int64.h"
/*
* In PSFTP our selects are synchronous, so these functions are
@ -118,7 +117,7 @@ struct RFile {
int fd;
};
RFile *open_existing_file(const char *name, uint64 *size,
RFile *open_existing_file(const char *name, uint64_t *size,
unsigned long *mtime, unsigned long *atime,
long *perms)
{
@ -140,8 +139,7 @@ RFile *open_existing_file(const char *name, uint64 *size,
}
if (size)
*size = uint64_make((statbuf.st_size >> 16) >> 16,
statbuf.st_size);
*size = statbuf.st_size;
if (mtime)
*mtime = statbuf.st_mtime;
@ -190,7 +188,7 @@ WFile *open_new_file(const char *name, long perms)
}
WFile *open_existing_wfile(const char *name, uint64 *size)
WFile *open_existing_wfile(const char *name, uint64_t *size)
{
int fd;
WFile *ret;
@ -210,8 +208,7 @@ WFile *open_existing_wfile(const char *name, uint64 *size)
memset(&statbuf, 0, sizeof(statbuf));
}
*size = uint64_make((statbuf.st_size >> 16) >> 16,
statbuf.st_size);
*size = statbuf.st_size;
}
return ret;
@ -260,13 +257,10 @@ void close_wfile(WFile *f)
/* Seek offset bytes through file, from whence, where whence is
FROM_START, FROM_CURRENT, or FROM_END */
int seek_file(WFile *f, uint64 offset, int whence)
int seek_file(WFile *f, uint64_t offset, int whence)
{
off_t fileofft;
int lseek_whence;
fileofft = (((off_t) offset.hi << 16) << 16) + offset.lo;
switch (whence) {
case FROM_START:
lseek_whence = SEEK_SET;
@ -281,19 +275,12 @@ int seek_file(WFile *f, uint64 offset, int whence)
return -1;
}
return lseek(f->fd, fileofft, lseek_whence) >= 0 ? 0 : -1;
return lseek(f->fd, offset, lseek_whence) >= 0 ? 0 : -1;
}
uint64 get_file_posn(WFile *f)
uint64_t get_file_posn(WFile *f)
{
off_t fileofft;
uint64 ret;
fileofft = lseek(f->fd, (off_t) 0, SEEK_CUR);
ret = uint64_make((fileofft >> 16) >> 16, fileofft);
return ret;
return lseek(f->fd, (off_t) 0, SEEK_CUR);
}
int file_type(const char *name)

View File

@ -356,11 +356,6 @@ static void uss_rename(SftpServer *srv, SftpReplyBuilder *reply,
}
}
static uint64 uint64_from_off_t(off_t off)
{
return uint64_make((off >> 16) >> 16, (off & 0xFFFFFFFFU));
}
static struct fxp_attrs uss_translate_struct_stat(const struct stat *st)
{
struct fxp_attrs attrs;
@ -370,7 +365,7 @@ static struct fxp_attrs uss_translate_struct_stat(const struct stat *st)
SSH_FILEXFER_ATTR_UIDGID |
SSH_FILEXFER_ATTR_ACMODTIME);
attrs.size = uint64_from_off_t(st->st_size);
attrs.size = st->st_size;
attrs.permissions = st->st_mode;
attrs.uid = st->st_uid;
attrs.gid = st->st_gid;
@ -421,11 +416,6 @@ static void uss_fstat(SftpServer *srv, SftpReplyBuilder *reply,
}
}
static off_t uint64_to_off_t(uint64 u)
{
return ((((off_t)u.hi) << 16) << 16) | (off_t)u.lo;
}
/*
* The guts of setstat and fsetstat, macroised so that they can call
* fchown(fd,...) or chown(path,...) depending on parameters.
@ -433,8 +423,7 @@ static off_t uint64_to_off_t(uint64 u)
#define SETSTAT_GUTS(api_prefix, api_arg, attrs, success) do \
{ \
if (attrs.flags & SSH_FILEXFER_ATTR_SIZE) \
if (api_prefix(truncate)( \
api_arg, uint64_to_off_t(attrs.size)) < 0) \
if (api_prefix(truncate)(api_arg, attrs.size) < 0) \
success = FALSE; \
if (attrs.flags & SSH_FILEXFER_ATTR_UIDGID) \
if (api_prefix(chown)(api_arg, attrs.uid, attrs.gid) < 0) \
@ -492,7 +481,7 @@ static void uss_fsetstat(SftpServer *srv, SftpReplyBuilder *reply,
}
static void uss_read(SftpServer *srv, SftpReplyBuilder *reply,
ptrlen handle, uint64 offset, unsigned length)
ptrlen handle, uint64_t offset, unsigned length)
{
UnixSftpServer *uss = container_of(srv, UnixSftpServer, srv);
int fd;
@ -513,7 +502,7 @@ static void uss_read(SftpServer *srv, SftpReplyBuilder *reply,
char *p = buf;
int status = lseek(fd, uint64_to_off_t(offset), SEEK_SET);
int status = lseek(fd, offset, SEEK_SET);
if (status >= 0 || errno == ESPIPE) {
int seekable = (status >= 0);
while (length > 0) {
@ -549,7 +538,7 @@ static void uss_read(SftpServer *srv, SftpReplyBuilder *reply,
}
static void uss_write(SftpServer *srv, SftpReplyBuilder *reply,
ptrlen handle, uint64 offset, ptrlen data)
ptrlen handle, uint64_t offset, ptrlen data)
{
UnixSftpServer *uss = container_of(srv, UnixSftpServer, srv);
int fd;
@ -560,7 +549,7 @@ static void uss_write(SftpServer *srv, SftpReplyBuilder *reply,
const char *p = data.ptr;
unsigned length = data.len;
int status = lseek(fd, uint64_to_off_t(offset), SEEK_SET);
int status = lseek(fd, offset, SEEK_SET);
if (status >= 0 || errno == ESPIPE) {
while (length > 0) {
@ -609,7 +598,7 @@ static void uss_readdir(SftpServer *srv, SftpReplyBuilder *reply,
#if defined HAVE_FSTATAT && defined HAVE_DIRFD
struct stat st;
if (!fstatat(dirfd(udh->dp), de->d_name, &st, AT_SYMLINK_NOFOLLOW)) {
char perms[11], sizebuf[32], *uidbuf = NULL, *gidbuf = NULL;
char perms[11], *uidbuf = NULL, *gidbuf = NULL;
struct passwd *pwd;
struct group *grp;
const char *user, *group;
@ -660,13 +649,11 @@ static void uss_readdir(SftpServer *srv, SftpReplyBuilder *reply,
else
group = gidbuf = dupprintf("%u", (unsigned)st.st_gid);
uint64_decimal(uint64_from_off_t(st.st_size), sizebuf);
tm = *localtime(&st.st_mtime);
longnamebuf = dupprintf(
"%s %3u %-8s %-8s %8s %.3s %2d %02d:%02d %s",
perms, (unsigned)st.st_nlink, user, group, sizebuf,
"%s %3u %-8s %-8s %8"PRIu64" %.3s %2d %02d:%02d %s",
perms, (unsigned)st.st_nlink, user, group, st.st_size,
(&"JanFebMarAprMayJunJulAugSepOctNovDec"[3*tm.tm_mon]),
tm.tm_mday, tm.tm_hour, tm.tm_min, de->d_name);
longname = ptrlen_from_asciz(longnamebuf);