Update the ioleast family to current coding conventions.
This commit is contained in:
parent
56267517ec
commit
577323b950
117
ext/ioleast.h
117
ext/ioleast.h
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
Copyright(C) Jonas 'Sortie' Termansen 2012, 2013.
|
Copyright(C) Jonas 'Sortie' Termansen 2012, 2013, 2015.
|
||||||
|
|
||||||
This file is part of the Sortix C Library.
|
This file is part of the Sortix C Library.
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -46,77 +47,83 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__attribute__((unused)) static inline
|
__attribute__((unused)) static inline
|
||||||
size_t readleast(int fd, void* buf, size_t least, size_t max)
|
size_t readleast(int fd, void* buf_ptr, size_t least, size_t max)
|
||||||
{
|
{
|
||||||
ssize_t amount = read(fd, buf, max);
|
assert(least <= max);
|
||||||
if ( amount < 0 )
|
unsigned char* buf = (unsigned char*) buf_ptr;
|
||||||
return 0;
|
size_t done = 0;
|
||||||
if ( least && !amount )
|
do
|
||||||
return errno = EEOF, 0;
|
|
||||||
if ( (size_t) amount < least )
|
|
||||||
{
|
{
|
||||||
void* nextbuf = (uint8_t*) buf + amount;
|
ssize_t amount = read(fd, buf + done, max - done);
|
||||||
size_t nextleast = least - amount;
|
if ( amount < 0 )
|
||||||
size_t nextmax = max - amount;
|
return done;
|
||||||
amount += readleast(fd, nextbuf, nextleast, nextmax);
|
if ( !amount && done < least )
|
||||||
}
|
return errno = EEOF, done;
|
||||||
return amount;
|
if ( !amount )
|
||||||
|
break;
|
||||||
|
done += amount;
|
||||||
|
} while ( done < least );
|
||||||
|
return done;
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((unused)) static inline
|
__attribute__((unused)) static inline
|
||||||
size_t writeleast(int fd, const void* buf, size_t least, size_t max)
|
size_t writeleast(int fd, const void* buf_ptr, size_t least, size_t max)
|
||||||
{
|
{
|
||||||
ssize_t amount = write(fd, buf, max);
|
assert(least <= max);
|
||||||
if ( amount < 0 )
|
const unsigned char* buf = (const unsigned char*) buf_ptr;
|
||||||
return 0;
|
size_t done = 0;
|
||||||
if ( least && !amount )
|
do
|
||||||
return errno = EEOF, 0;
|
|
||||||
if ( (size_t) amount < least )
|
|
||||||
{
|
{
|
||||||
const void* nextbuf = (const uint8_t*) buf + amount;
|
ssize_t amount = write(fd, buf + done, max - done);
|
||||||
size_t nextleast = least - amount;
|
if ( amount < 0 )
|
||||||
size_t nextmax = max - amount;
|
return done;
|
||||||
amount += writeleast(fd, nextbuf, nextleast, nextmax);
|
if ( !amount && done < least )
|
||||||
}
|
return errno = EEOF, done;
|
||||||
return amount;
|
if ( !amount )
|
||||||
|
break;
|
||||||
|
done += amount;
|
||||||
|
} while ( done < least );
|
||||||
|
return done;
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((unused)) static inline
|
__attribute__((unused)) static inline
|
||||||
size_t preadleast(int fd, void* buf, size_t least, size_t max, off_t off)
|
size_t preadleast(int fd, void* buf_ptr, size_t least, size_t max, off_t off)
|
||||||
{
|
{
|
||||||
ssize_t amount = pread(fd, buf, max, off);
|
assert(least <= max);
|
||||||
if ( amount < 0 )
|
unsigned char* buf = (unsigned char*) buf_ptr;
|
||||||
return 0;
|
size_t done = 0;
|
||||||
if ( least && !amount )
|
do
|
||||||
return errno = EEOF, 0;
|
|
||||||
if ( (size_t) amount < least )
|
|
||||||
{
|
{
|
||||||
void* nextbuf = (uint8_t*) buf + amount;
|
ssize_t amount = pread(fd, buf + done, max - done, off + done);
|
||||||
size_t nextleast = least - amount;
|
if ( amount < 0 )
|
||||||
size_t nextmax = max - amount;
|
return done;
|
||||||
off_t nextoff = off + amount;
|
if ( !amount && done < least )
|
||||||
amount += preadleast(fd, nextbuf, nextleast, nextmax, nextoff);
|
return errno = EEOF, done;
|
||||||
}
|
if ( !amount )
|
||||||
return amount;
|
break;
|
||||||
|
done += amount;
|
||||||
|
} while ( done < least );
|
||||||
|
return done;
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((unused)) static inline
|
__attribute__((unused)) static inline
|
||||||
size_t pwriteleast(int fd, const void* buf, size_t least, size_t max, off_t off)
|
size_t pwriteleast(int fd, const void* buf_ptr, size_t least, size_t max, off_t off)
|
||||||
{
|
{
|
||||||
ssize_t amount = pwrite(fd, buf, max, off);
|
assert(least <= max);
|
||||||
if ( amount < 0 )
|
const unsigned char* buf = (const unsigned char*) buf_ptr;
|
||||||
return 0;
|
size_t done = 0;
|
||||||
if ( least && !amount )
|
do
|
||||||
return errno = EEOF, 0;
|
|
||||||
if ( (size_t) amount < least )
|
|
||||||
{
|
{
|
||||||
const void* nextbuf = (const uint8_t*) buf + amount;
|
ssize_t amount = pwrite(fd, buf + done, max - done, off + done);
|
||||||
size_t nextleast = least - amount;
|
if ( amount < 0 )
|
||||||
size_t nextmax = max - amount;
|
return done;
|
||||||
off_t nextoff = off + amount;
|
if ( !amount && done < least )
|
||||||
amount += pwriteleast(fd, nextbuf, nextleast, nextmax, nextoff);
|
return errno = EEOF, done;
|
||||||
}
|
if ( !amount )
|
||||||
return amount;
|
break;
|
||||||
|
done += amount;
|
||||||
|
} while ( done < least );
|
||||||
|
return done;
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((unused)) static inline
|
__attribute__((unused)) static inline
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
Copyright(C) Jonas 'Sortie' Termansen 2012, 2013.
|
Copyright(C) Jonas 'Sortie' Termansen 2012, 2013, 2015.
|
||||||
|
|
||||||
This file is part of the Sortix C Library.
|
This file is part of the Sortix C Library.
|
||||||
|
|
||||||
|
@ -22,26 +22,28 @@
|
||||||
|
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <ioleast.h>
|
#include <ioleast.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
size_t preadleast(int fd, void* buf, size_t least, size_t max, off_t off)
|
size_t preadleast(int fd, void* buf_ptr, size_t least, size_t max, off_t off)
|
||||||
{
|
{
|
||||||
ssize_t amount = pread(fd, buf, max, off);
|
assert(least <= max);
|
||||||
if ( amount < 0 )
|
unsigned char* buf = (unsigned char*) buf_ptr;
|
||||||
return 0;
|
size_t done = 0;
|
||||||
if ( least && !amount )
|
do
|
||||||
return errno = EEOF, 0;
|
|
||||||
if ( (size_t) amount < least )
|
|
||||||
{
|
{
|
||||||
void* nextbuf = (uint8_t*) buf + amount;
|
ssize_t amount = pread(fd, buf + done, max - done, off + done);
|
||||||
size_t nextleast = least - amount;
|
if ( amount < 0 )
|
||||||
size_t nextmax = max - amount;
|
return done;
|
||||||
off_t nextoff = off + amount;
|
if ( !amount && done < least )
|
||||||
amount += preadleast(fd, nextbuf, nextleast, nextmax, nextoff);
|
return errno = EEOF, done;
|
||||||
}
|
if ( !amount )
|
||||||
return amount;
|
break;
|
||||||
|
done += amount;
|
||||||
|
} while ( done < least );
|
||||||
|
return done;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
Copyright(C) Jonas 'Sortie' Termansen 2012, 2013.
|
Copyright(C) Jonas 'Sortie' Termansen 2012, 2013, 2015.
|
||||||
|
|
||||||
This file is part of the Sortix C Library.
|
This file is part of the Sortix C Library.
|
||||||
|
|
||||||
|
@ -22,26 +22,28 @@
|
||||||
|
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <ioleast.h>
|
#include <ioleast.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
size_t pwriteleast(int fd, const void* buf, size_t least, size_t max, off_t off)
|
size_t pwriteleast(int fd, const void* buf_ptr, size_t least, size_t max, off_t off)
|
||||||
{
|
{
|
||||||
ssize_t amount = pwrite(fd, buf, max, off);
|
assert(least <= max);
|
||||||
if ( amount < 0 )
|
const unsigned char* buf = (const unsigned char*) buf_ptr;
|
||||||
return 0;
|
size_t done = 0;
|
||||||
if ( least && !amount )
|
do
|
||||||
return errno = EEOF, 0;
|
|
||||||
if ( (size_t) amount < least )
|
|
||||||
{
|
{
|
||||||
const void* nextbuf = (const uint8_t*) buf + amount;
|
ssize_t amount = pwrite(fd, buf + done, max - done, off + done);
|
||||||
size_t nextleast = least - amount;
|
if ( amount < 0 )
|
||||||
size_t nextmax = max - amount;
|
return done;
|
||||||
off_t nextoff = off + amount;
|
if ( !amount && done < least )
|
||||||
amount += pwriteleast(fd, nextbuf, nextleast, nextmax, nextoff);
|
return errno = EEOF, done;
|
||||||
}
|
if ( !amount )
|
||||||
return amount;
|
break;
|
||||||
|
done += amount;
|
||||||
|
} while ( done < least );
|
||||||
|
return done;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
Copyright(C) Jonas 'Sortie' Termansen 2012, 2013.
|
Copyright(C) Jonas 'Sortie' Termansen 2012, 2013, 2015.
|
||||||
|
|
||||||
This file is part of the Sortix C Library.
|
This file is part of the Sortix C Library.
|
||||||
|
|
||||||
|
@ -22,24 +22,28 @@
|
||||||
|
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <ioleast.h>
|
#include <ioleast.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
extern "C" size_t readleast(int fd, void* buf, size_t least, size_t max)
|
extern "C"
|
||||||
|
size_t readleast(int fd, void* buf_ptr, size_t least, size_t max)
|
||||||
{
|
{
|
||||||
ssize_t amount = read(fd, buf, max);
|
assert(least <= max);
|
||||||
if ( amount < 0 )
|
unsigned char* buf = (unsigned char*) buf_ptr;
|
||||||
return 0;
|
size_t done = 0;
|
||||||
if ( least && !amount )
|
do
|
||||||
return errno = EEOF, 0;
|
|
||||||
if ( (size_t) amount < least )
|
|
||||||
{
|
{
|
||||||
void* nextbuf = (uint8_t*) buf + amount;
|
ssize_t amount = read(fd, buf + done, max - done);
|
||||||
size_t nextleast = least - amount;
|
if ( amount < 0 )
|
||||||
size_t nextmax = max - amount;
|
return done;
|
||||||
amount += readleast(fd, nextbuf, nextleast, nextmax);
|
if ( !amount && done < least )
|
||||||
}
|
return errno = EEOF, done;
|
||||||
return amount;
|
if ( !amount )
|
||||||
|
break;
|
||||||
|
done += amount;
|
||||||
|
} while ( done < least );
|
||||||
|
return done;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
Copyright(C) Jonas 'Sortie' Termansen 2012, 2013.
|
Copyright(C) Jonas 'Sortie' Termansen 2012, 2013, 2015.
|
||||||
|
|
||||||
This file is part of the Sortix C Library.
|
This file is part of the Sortix C Library.
|
||||||
|
|
||||||
|
@ -22,24 +22,28 @@
|
||||||
|
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <ioleast.h>
|
#include <ioleast.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
extern "C" size_t writeleast(int fd, const void* buf, size_t least, size_t max)
|
extern "C"
|
||||||
|
size_t writeleast(int fd, const void* buf_ptr, size_t least, size_t max)
|
||||||
{
|
{
|
||||||
ssize_t amount = write(fd, buf, max);
|
assert(least <= max);
|
||||||
if ( amount < 0 )
|
const unsigned char* buf = (const unsigned char*) buf_ptr;
|
||||||
return 0;
|
size_t done = 0;
|
||||||
if ( least && !amount )
|
do
|
||||||
return errno = EEOF, 0;
|
|
||||||
if ( (size_t) amount < least )
|
|
||||||
{
|
{
|
||||||
const void* nextbuf = (const uint8_t*) buf + amount;
|
ssize_t amount = write(fd, buf + done, max - done);
|
||||||
size_t nextleast = least - amount;
|
if ( amount < 0 )
|
||||||
size_t nextmax = max - amount;
|
return done;
|
||||||
amount += writeleast(fd, nextbuf, nextleast, nextmax);
|
if ( !amount && done < least )
|
||||||
}
|
return errno = EEOF, done;
|
||||||
return amount;
|
if ( !amount )
|
||||||
|
break;
|
||||||
|
done += amount;
|
||||||
|
} while ( done < least );
|
||||||
|
return done;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
Copyright(C) Jonas 'Sortie' Termansen 2012, 2013.
|
Copyright(C) Jonas 'Sortie' Termansen 2012, 2013, 2015.
|
||||||
|
|
||||||
This file is part of the Sortix C Library.
|
This file is part of the Sortix C Library.
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -46,77 +47,83 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__attribute__((unused)) static inline
|
__attribute__((unused)) static inline
|
||||||
size_t readleast(int fd, void* buf, size_t least, size_t max)
|
size_t readleast(int fd, void* buf_ptr, size_t least, size_t max)
|
||||||
{
|
{
|
||||||
ssize_t amount = read(fd, buf, max);
|
assert(least <= max);
|
||||||
if ( amount < 0 )
|
unsigned char* buf = (unsigned char*) buf_ptr;
|
||||||
return 0;
|
size_t done = 0;
|
||||||
if ( least && !amount )
|
do
|
||||||
return errno = EEOF, 0;
|
|
||||||
if ( (size_t) amount < least )
|
|
||||||
{
|
{
|
||||||
void* nextbuf = (uint8_t*) buf + amount;
|
ssize_t amount = read(fd, buf + done, max - done);
|
||||||
size_t nextleast = least - amount;
|
if ( amount < 0 )
|
||||||
size_t nextmax = max - amount;
|
return done;
|
||||||
amount += readleast(fd, nextbuf, nextleast, nextmax);
|
if ( !amount && done < least )
|
||||||
}
|
return errno = EEOF, done;
|
||||||
return amount;
|
if ( !amount )
|
||||||
|
break;
|
||||||
|
done += amount;
|
||||||
|
} while ( done < least );
|
||||||
|
return done;
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((unused)) static inline
|
__attribute__((unused)) static inline
|
||||||
size_t writeleast(int fd, const void* buf, size_t least, size_t max)
|
size_t writeleast(int fd, const void* buf_ptr, size_t least, size_t max)
|
||||||
{
|
{
|
||||||
ssize_t amount = write(fd, buf, max);
|
assert(least <= max);
|
||||||
if ( amount < 0 )
|
const unsigned char* buf = (const unsigned char*) buf_ptr;
|
||||||
return 0;
|
size_t done = 0;
|
||||||
if ( least && !amount )
|
do
|
||||||
return errno = EEOF, 0;
|
|
||||||
if ( (size_t) amount < least )
|
|
||||||
{
|
{
|
||||||
const void* nextbuf = (const uint8_t*) buf + amount;
|
ssize_t amount = write(fd, buf + done, max - done);
|
||||||
size_t nextleast = least - amount;
|
if ( amount < 0 )
|
||||||
size_t nextmax = max - amount;
|
return done;
|
||||||
amount += writeleast(fd, nextbuf, nextleast, nextmax);
|
if ( !amount && done < least )
|
||||||
}
|
return errno = EEOF, done;
|
||||||
return amount;
|
if ( !amount )
|
||||||
|
break;
|
||||||
|
done += amount;
|
||||||
|
} while ( done < least );
|
||||||
|
return done;
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((unused)) static inline
|
__attribute__((unused)) static inline
|
||||||
size_t preadleast(int fd, void* buf, size_t least, size_t max, off_t off)
|
size_t preadleast(int fd, void* buf_ptr, size_t least, size_t max, off_t off)
|
||||||
{
|
{
|
||||||
ssize_t amount = pread(fd, buf, max, off);
|
assert(least <= max);
|
||||||
if ( amount < 0 )
|
unsigned char* buf = (unsigned char*) buf_ptr;
|
||||||
return 0;
|
size_t done = 0;
|
||||||
if ( least && !amount )
|
do
|
||||||
return errno = EEOF, 0;
|
|
||||||
if ( (size_t) amount < least )
|
|
||||||
{
|
{
|
||||||
void* nextbuf = (uint8_t*) buf + amount;
|
ssize_t amount = pread(fd, buf + done, max - done, off + done);
|
||||||
size_t nextleast = least - amount;
|
if ( amount < 0 )
|
||||||
size_t nextmax = max - amount;
|
return done;
|
||||||
off_t nextoff = off + amount;
|
if ( !amount && done < least )
|
||||||
amount += preadleast(fd, nextbuf, nextleast, nextmax, nextoff);
|
return errno = EEOF, done;
|
||||||
}
|
if ( !amount )
|
||||||
return amount;
|
break;
|
||||||
|
done += amount;
|
||||||
|
} while ( done < least );
|
||||||
|
return done;
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((unused)) static inline
|
__attribute__((unused)) static inline
|
||||||
size_t pwriteleast(int fd, const void* buf, size_t least, size_t max, off_t off)
|
size_t pwriteleast(int fd, const void* buf_ptr, size_t least, size_t max, off_t off)
|
||||||
{
|
{
|
||||||
ssize_t amount = pwrite(fd, buf, max, off);
|
assert(least <= max);
|
||||||
if ( amount < 0 )
|
const unsigned char* buf = (const unsigned char*) buf_ptr;
|
||||||
return 0;
|
size_t done = 0;
|
||||||
if ( least && !amount )
|
do
|
||||||
return errno = EEOF, 0;
|
|
||||||
if ( (size_t) amount < least )
|
|
||||||
{
|
{
|
||||||
const void* nextbuf = (const uint8_t*) buf + amount;
|
ssize_t amount = pwrite(fd, buf + done, max - done, off + done);
|
||||||
size_t nextleast = least - amount;
|
if ( amount < 0 )
|
||||||
size_t nextmax = max - amount;
|
return done;
|
||||||
off_t nextoff = off + amount;
|
if ( !amount && done < least )
|
||||||
amount += pwriteleast(fd, nextbuf, nextleast, nextmax, nextoff);
|
return errno = EEOF, done;
|
||||||
}
|
if ( !amount )
|
||||||
return amount;
|
break;
|
||||||
|
done += amount;
|
||||||
|
} while ( done < least );
|
||||||
|
return done;
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((unused)) static inline
|
__attribute__((unused)) static inline
|
||||||
|
|
Loading…
Reference in New Issue