Update the ioleast family to current coding conventions.

This commit is contained in:
Jonas 'Sortie' Termansen 2015-02-04 18:21:18 +01:00
parent 56267517ec
commit 577323b950
6 changed files with 194 additions and 168 deletions

View File

@ -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.
@ -36,6 +36,7 @@
#include <sys/types.h>
#include <assert.h>
#include <errno.h>
#include <stddef.h>
#include <stdint.h>
@ -46,77 +47,83 @@
#endif
__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);
if ( amount < 0 )
return 0;
if ( least && !amount )
return errno = EEOF, 0;
if ( (size_t) amount < least )
assert(least <= max);
unsigned char* buf = (unsigned char*) buf_ptr;
size_t done = 0;
do
{
void* nextbuf = (uint8_t*) buf + amount;
size_t nextleast = least - amount;
size_t nextmax = max - amount;
amount += readleast(fd, nextbuf, nextleast, nextmax);
}
return amount;
ssize_t amount = read(fd, buf + done, max - done);
if ( amount < 0 )
return done;
if ( !amount && done < least )
return errno = EEOF, done;
if ( !amount )
break;
done += amount;
} while ( done < least );
return done;
}
__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);
if ( amount < 0 )
return 0;
if ( least && !amount )
return errno = EEOF, 0;
if ( (size_t) amount < least )
assert(least <= max);
const unsigned char* buf = (const unsigned char*) buf_ptr;
size_t done = 0;
do
{
const void* nextbuf = (const uint8_t*) buf + amount;
size_t nextleast = least - amount;
size_t nextmax = max - amount;
amount += writeleast(fd, nextbuf, nextleast, nextmax);
}
return amount;
ssize_t amount = write(fd, buf + done, max - done);
if ( amount < 0 )
return done;
if ( !amount && done < least )
return errno = EEOF, done;
if ( !amount )
break;
done += amount;
} while ( done < least );
return done;
}
__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);
if ( amount < 0 )
return 0;
if ( least && !amount )
return errno = EEOF, 0;
if ( (size_t) amount < least )
assert(least <= max);
unsigned char* buf = (unsigned char*) buf_ptr;
size_t done = 0;
do
{
void* nextbuf = (uint8_t*) buf + amount;
size_t nextleast = least - amount;
size_t nextmax = max - amount;
off_t nextoff = off + amount;
amount += preadleast(fd, nextbuf, nextleast, nextmax, nextoff);
}
return amount;
ssize_t amount = pread(fd, buf + done, max - done, off + done);
if ( amount < 0 )
return done;
if ( !amount && done < least )
return errno = EEOF, done;
if ( !amount )
break;
done += amount;
} while ( done < least );
return done;
}
__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);
if ( amount < 0 )
return 0;
if ( least && !amount )
return errno = EEOF, 0;
if ( (size_t) amount < least )
assert(least <= max);
const unsigned char* buf = (const unsigned char*) buf_ptr;
size_t done = 0;
do
{
const void* nextbuf = (const uint8_t*) buf + amount;
size_t nextleast = least - amount;
size_t nextmax = max - amount;
off_t nextoff = off + amount;
amount += pwriteleast(fd, nextbuf, nextleast, nextmax, nextoff);
}
return amount;
ssize_t amount = pwrite(fd, buf + done, max - done, off + done);
if ( amount < 0 )
return done;
if ( !amount && done < least )
return errno = EEOF, done;
if ( !amount )
break;
done += amount;
} while ( done < least );
return done;
}
__attribute__((unused)) static inline

View File

@ -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.
@ -22,26 +22,28 @@
*******************************************************************************/
#include <assert.h>
#include <errno.h>
#include <ioleast.h>
#include <stdint.h>
#include <unistd.h>
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);
if ( amount < 0 )
return 0;
if ( least && !amount )
return errno = EEOF, 0;
if ( (size_t) amount < least )
assert(least <= max);
unsigned char* buf = (unsigned char*) buf_ptr;
size_t done = 0;
do
{
void* nextbuf = (uint8_t*) buf + amount;
size_t nextleast = least - amount;
size_t nextmax = max - amount;
off_t nextoff = off + amount;
amount += preadleast(fd, nextbuf, nextleast, nextmax, nextoff);
}
return amount;
ssize_t amount = pread(fd, buf + done, max - done, off + done);
if ( amount < 0 )
return done;
if ( !amount && done < least )
return errno = EEOF, done;
if ( !amount )
break;
done += amount;
} while ( done < least );
return done;
}

View File

@ -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.
@ -22,26 +22,28 @@
*******************************************************************************/
#include <assert.h>
#include <errno.h>
#include <ioleast.h>
#include <stdint.h>
#include <unistd.h>
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);
if ( amount < 0 )
return 0;
if ( least && !amount )
return errno = EEOF, 0;
if ( (size_t) amount < least )
assert(least <= max);
const unsigned char* buf = (const unsigned char*) buf_ptr;
size_t done = 0;
do
{
const void* nextbuf = (const uint8_t*) buf + amount;
size_t nextleast = least - amount;
size_t nextmax = max - amount;
off_t nextoff = off + amount;
amount += pwriteleast(fd, nextbuf, nextleast, nextmax, nextoff);
}
return amount;
ssize_t amount = pwrite(fd, buf + done, max - done, off + done);
if ( amount < 0 )
return done;
if ( !amount && done < least )
return errno = EEOF, done;
if ( !amount )
break;
done += amount;
} while ( done < least );
return done;
}

View File

@ -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.
@ -22,24 +22,28 @@
*******************************************************************************/
#include <assert.h>
#include <errno.h>
#include <ioleast.h>
#include <stdint.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);
if ( amount < 0 )
return 0;
if ( least && !amount )
return errno = EEOF, 0;
if ( (size_t) amount < least )
assert(least <= max);
unsigned char* buf = (unsigned char*) buf_ptr;
size_t done = 0;
do
{
void* nextbuf = (uint8_t*) buf + amount;
size_t nextleast = least - amount;
size_t nextmax = max - amount;
amount += readleast(fd, nextbuf, nextleast, nextmax);
}
return amount;
ssize_t amount = read(fd, buf + done, max - done);
if ( amount < 0 )
return done;
if ( !amount && done < least )
return errno = EEOF, done;
if ( !amount )
break;
done += amount;
} while ( done < least );
return done;
}

View File

@ -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.
@ -22,24 +22,28 @@
*******************************************************************************/
#include <assert.h>
#include <errno.h>
#include <ioleast.h>
#include <stdint.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);
if ( amount < 0 )
return 0;
if ( least && !amount )
return errno = EEOF, 0;
if ( (size_t) amount < least )
assert(least <= max);
const unsigned char* buf = (const unsigned char*) buf_ptr;
size_t done = 0;
do
{
const void* nextbuf = (const uint8_t*) buf + amount;
size_t nextleast = least - amount;
size_t nextmax = max - amount;
amount += writeleast(fd, nextbuf, nextleast, nextmax);
}
return amount;
ssize_t amount = write(fd, buf + done, max - done);
if ( amount < 0 )
return done;
if ( !amount && done < least )
return errno = EEOF, done;
if ( !amount )
break;
done += amount;
} while ( done < least );
return done;
}

View File

@ -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.
@ -36,6 +36,7 @@
#include <sys/types.h>
#include <assert.h>
#include <errno.h>
#include <stddef.h>
#include <stdint.h>
@ -46,77 +47,83 @@
#endif
__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);
if ( amount < 0 )
return 0;
if ( least && !amount )
return errno = EEOF, 0;
if ( (size_t) amount < least )
assert(least <= max);
unsigned char* buf = (unsigned char*) buf_ptr;
size_t done = 0;
do
{
void* nextbuf = (uint8_t*) buf + amount;
size_t nextleast = least - amount;
size_t nextmax = max - amount;
amount += readleast(fd, nextbuf, nextleast, nextmax);
}
return amount;
ssize_t amount = read(fd, buf + done, max - done);
if ( amount < 0 )
return done;
if ( !amount && done < least )
return errno = EEOF, done;
if ( !amount )
break;
done += amount;
} while ( done < least );
return done;
}
__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);
if ( amount < 0 )
return 0;
if ( least && !amount )
return errno = EEOF, 0;
if ( (size_t) amount < least )
assert(least <= max);
const unsigned char* buf = (const unsigned char*) buf_ptr;
size_t done = 0;
do
{
const void* nextbuf = (const uint8_t*) buf + amount;
size_t nextleast = least - amount;
size_t nextmax = max - amount;
amount += writeleast(fd, nextbuf, nextleast, nextmax);
}
return amount;
ssize_t amount = write(fd, buf + done, max - done);
if ( amount < 0 )
return done;
if ( !amount && done < least )
return errno = EEOF, done;
if ( !amount )
break;
done += amount;
} while ( done < least );
return done;
}
__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);
if ( amount < 0 )
return 0;
if ( least && !amount )
return errno = EEOF, 0;
if ( (size_t) amount < least )
assert(least <= max);
unsigned char* buf = (unsigned char*) buf_ptr;
size_t done = 0;
do
{
void* nextbuf = (uint8_t*) buf + amount;
size_t nextleast = least - amount;
size_t nextmax = max - amount;
off_t nextoff = off + amount;
amount += preadleast(fd, nextbuf, nextleast, nextmax, nextoff);
}
return amount;
ssize_t amount = pread(fd, buf + done, max - done, off + done);
if ( amount < 0 )
return done;
if ( !amount && done < least )
return errno = EEOF, done;
if ( !amount )
break;
done += amount;
} while ( done < least );
return done;
}
__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);
if ( amount < 0 )
return 0;
if ( least && !amount )
return errno = EEOF, 0;
if ( (size_t) amount < least )
assert(least <= max);
const unsigned char* buf = (const unsigned char*) buf_ptr;
size_t done = 0;
do
{
const void* nextbuf = (const uint8_t*) buf + amount;
size_t nextleast = least - amount;
size_t nextmax = max - amount;
off_t nextoff = off + amount;
amount += pwriteleast(fd, nextbuf, nextleast, nextmax, nextoff);
}
return amount;
ssize_t amount = pwrite(fd, buf + done, max - done, off + done);
if ( amount < 0 )
return done;
if ( !amount && done < least )
return errno = EEOF, done;
if ( !amount )
break;
done += amount;
} while ( done < least );
return done;
}
__attribute__((unused)) static inline