cleanup code indent
Cleanup the code indent using:
find . -name *.c -exec Lindent {} \;
It's really a big change, but can fix almost all of
the indent problem in C code, although we can't
ensure all of the changes are right, but the error
changes are really few.
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
diff --git a/lib/cloner.c b/lib/cloner.c
index 2be2216..990a562 100644
--- a/lib/cloner.c
+++ b/lib/cloner.c
@@ -23,24 +23,24 @@
#include <stdio.h>
#include <errno.h>
-#include <unistd.h> /* fork, getpid, sleep */
+#include <unistd.h> /* fork, getpid, sleep */
#include <string.h>
-#include <stdlib.h> /* exit */
-#include <sched.h> /* clone */
+#include <stdlib.h> /* exit */
+#include <sched.h> /* clone */
#include "test.h"
-#undef clone /* we want to use clone() */
+#undef clone /* we want to use clone() */
/* copied from several other files under ltp */
#if defined (__s390__) || (__s390x__)
#define clone __clone
-extern int __clone(int(void*),void*,int,void*);
+extern int __clone(int (void *), void *, int, void *);
#elif defined(__ia64__)
#define clone2 __clone2
/* Prototype provided by David Mosberger */
-extern int __clone2(int (*fn) (void *arg), void *child_stack_base,
- size_t child_stack_size, int flags, void *arg,
- pid_t *parent_tid, void *tls, pid_t *child_tid);
+extern int __clone2(int (*fn) (void *arg), void *child_stack_base,
+ size_t child_stack_size, int flags, void *arg,
+ pid_t * parent_tid, void *tls, pid_t * child_tid);
#endif
/***********************************************************************
@@ -50,8 +50,8 @@
* 3. all others take top of stack (stack grows down)
***********************************************************************/
int
-ltp_clone(unsigned long clone_flags, int (*fn)(void *arg), void *arg,
- size_t stack_size, void *stack)
+ltp_clone(unsigned long clone_flags, int (*fn) (void *arg), void *arg,
+ size_t stack_size, void *stack)
{
int ret;
@@ -64,8 +64,7 @@
* For archs where stack grows downwards, stack points to the topmost
* address of the memory space set up for the child stack.
*/
- ret = clone(fn, (stack ? stack + stack_size : NULL),
- clone_flags, arg);
+ ret = clone(fn, (stack ? stack + stack_size : NULL), clone_flags, arg);
#endif
return ret;
@@ -76,8 +75,8 @@
* caller-specified size.
***********************************************************************/
int
-ltp_clone_malloc(unsigned long clone_flags, int (*fn)(void *arg), void *arg,
- size_t stack_size)
+ltp_clone_malloc(unsigned long clone_flags, int (*fn) (void *arg), void *arg,
+ size_t stack_size)
{
void *stack;
int ret;
@@ -102,8 +101,7 @@
* Experience thus far suggests that one page is often insufficient,
* while 6*getpagesize() seems adequate.
***********************************************************************/
-int
-ltp_clone_quick(unsigned long clone_flags, int (*fn)(void *arg), void *arg)
+int ltp_clone_quick(unsigned long clone_flags, int (*fn) (void *arg), void *arg)
{
size_t stack_size = getpagesize() * 6;
diff --git a/lib/dataascii.c b/lib/dataascii.c
index 60d1a38..5c577a9 100644
--- a/lib/dataascii.c
+++ b/lib/dataascii.c
@@ -37,181 +37,188 @@
#define CHARS_SIZE sizeof(CHARS)
#ifdef UNIT_TEST
-#include <stdlib.h> /* malloc */
+#include <stdlib.h> /* malloc */
#endif
static char Errmsg[80];
-int
-dataasciigen(listofchars, buffer, bsize, offset)
-char *listofchars; /* a null terminated list of characters */
+int dataasciigen(listofchars, buffer, bsize, offset)
+char *listofchars; /* a null terminated list of characters */
char *buffer;
int bsize;
int offset;
{
- int cnt;
- int total;
- int ind; /* index into CHARS array */
- char *chr;
- int chars_size;
- char *charlist;
+ int cnt;
+ int total;
+ int ind; /* index into CHARS array */
+ char *chr;
+ int chars_size;
+ char *charlist;
- chr=buffer;
- total=offset+bsize;
+ chr = buffer;
+ total = offset + bsize;
if (listofchars == NULL) {
- charlist=CHARS;
- chars_size=CHARS_SIZE;
- }
- else {
- charlist=listofchars;
- chars_size=strlen(listofchars);
+ charlist = CHARS;
+ chars_size = CHARS_SIZE;
+ } else {
+ charlist = listofchars;
+ chars_size = strlen(listofchars);
}
- for (cnt=offset; cnt<total; cnt++) {
- ind=cnt%chars_size;
- *chr++=charlist[ind];
+ for (cnt = offset; cnt < total; cnt++) {
+ ind = cnt % chars_size;
+ *chr++ = charlist[ind];
}
return bsize;
-} /* end of dataasciigen */
+} /* end of dataasciigen */
-int
-dataasciichk(listofchars, buffer, bsize, offset, errmsg)
-char *listofchars; /* a null terminated list of characters */
+int dataasciichk(listofchars, buffer, bsize, offset, errmsg)
+char *listofchars; /* a null terminated list of characters */
char *buffer;
int bsize;
int offset;
char **errmsg;
{
- int cnt;
- int total;
- int ind; /* index into CHARS array */
- char *chr;
- int chars_size;
- char *charlist;
+ int cnt;
+ int total;
+ int ind; /* index into CHARS array */
+ char *chr;
+ int chars_size;
+ char *charlist;
- chr=buffer;
- total=offset+bsize;
+ chr = buffer;
+ total = offset + bsize;
if (listofchars == NULL) {
- charlist=CHARS;
- chars_size=CHARS_SIZE;
- }
- else {
- charlist=listofchars;
- chars_size=strlen(listofchars);
+ charlist = CHARS;
+ chars_size = CHARS_SIZE;
+ } else {
+ charlist = listofchars;
+ chars_size = strlen(listofchars);
}
if (errmsg != NULL) {
- *errmsg = Errmsg;
+ *errmsg = Errmsg;
}
- for (cnt=offset; cnt<total; chr++, cnt++) {
- ind=cnt%chars_size;
- if (*chr != charlist[ind]) {
- sprintf(Errmsg,
- "data mismatch at offset %d, exp:%#o, act:%#o", cnt,
- charlist[ind], *chr);
- return cnt;
- }
+ for (cnt = offset; cnt < total; chr++, cnt++) {
+ ind = cnt % chars_size;
+ if (*chr != charlist[ind]) {
+ sprintf(Errmsg,
+ "data mismatch at offset %d, exp:%#o, act:%#o",
+ cnt, charlist[ind], *chr);
+ return cnt;
+ }
}
sprintf(Errmsg, "all %d bytes match desired pattern", bsize);
- return -1; /* buffer is ok */
+ return -1; /* buffer is ok */
-} /* end of dataasciichk */
-
+} /* end of dataasciichk */
#if UNIT_TEST
/***********************************************************************
* main for doing unit testing
***********************************************************************/
-int
-main(ac, ag)
+int main(ac, ag)
int ac;
char **ag;
{
-int size=1023;
-char *buffer;
-int ret;
-char *errmsg;
+ int size = 1023;
+ char *buffer;
+ int ret;
+ char *errmsg;
- if ((buffer=(char *)malloc(size)) == NULL) {
- perror("malloc");
- exit(2);
- }
+ if ((buffer = (char *)malloc(size)) == NULL) {
+ perror("malloc");
+ exit(2);
+ }
- dataasciigen(NULL, buffer, size, 0);
- printf("dataasciigen(NULL, buffer, %d, 0)\n", size);
+ dataasciigen(NULL, buffer, size, 0);
+ printf("dataasciigen(NULL, buffer, %d, 0)\n", size);
- ret=dataasciichk(NULL, buffer, size, 0, &errmsg);
- printf("dataasciichk(NULL, buffer, %d, 0, &errmsg) returned %d %s\n",
- size, ret, errmsg);
+ ret = dataasciichk(NULL, buffer, size, 0, &errmsg);
+ printf("dataasciichk(NULL, buffer, %d, 0, &errmsg) returned %d %s\n",
+ size, ret, errmsg);
- if (ret == -1)
- printf("\tPASS return value is -1 as expected\n");
- else
- printf("\tFAIL return value is %d, expected -1\n", ret);
+ if (ret == -1)
+ printf("\tPASS return value is -1 as expected\n");
+ else
+ printf("\tFAIL return value is %d, expected -1\n", ret);
- ret=dataasciichk(NULL, &buffer[1], size-1, 1, &errmsg);
- printf("dataasciichk(NULL, &buffer[1], %d, 1, &errmsg) returned %d %s\n",
- size-1, ret, errmsg);
+ ret = dataasciichk(NULL, &buffer[1], size - 1, 1, &errmsg);
+ printf
+ ("dataasciichk(NULL, &buffer[1], %d, 1, &errmsg) returned %d %s\n",
+ size - 1, ret, errmsg);
- if (ret == -1)
- printf("\tPASS return value is -1 as expected\n");
- else
- printf("\tFAIL return value is %d, expected -1\n", ret);
+ if (ret == -1)
+ printf("\tPASS return value is -1 as expected\n");
+ else
+ printf("\tFAIL return value is %d, expected -1\n", ret);
- buffer[25]= 0x0;
- printf("changing char 25\n");
+ buffer[25] = 0x0;
+ printf("changing char 25\n");
- ret=dataasciichk(NULL, &buffer[1], size-1, 1, &errmsg);
- printf("dataasciichk(NULL, &buffer[1], %d, 1, &errmsg) returned %d %s\n",
- size-1, ret, errmsg);
+ ret = dataasciichk(NULL, &buffer[1], size - 1, 1, &errmsg);
+ printf
+ ("dataasciichk(NULL, &buffer[1], %d, 1, &errmsg) returned %d %s\n",
+ size - 1, ret, errmsg);
- if (ret == 25)
- printf("\tPASS return value is 25 as expected\n");
- else
- printf("\tFAIL return value is %d, expected 25\n", ret);
+ if (ret == 25)
+ printf("\tPASS return value is 25 as expected\n");
+ else
+ printf("\tFAIL return value is %d, expected 25\n", ret);
- dataasciigen("this is a test of the my string" , buffer, size, 0);
- printf("dataasciigen(\"this is a test of the my string\", buffer, %d, 0)\n", size);
+ dataasciigen("this is a test of the my string", buffer, size, 0);
+ printf
+ ("dataasciigen(\"this is a test of the my string\", buffer, %d, 0)\n",
+ size);
- ret=dataasciichk("this is a test of the my string", buffer, size, 0, &errmsg);
- printf("dataasciichk(\"this is a test of the my string\", buffer, %d, 0, &errmsg) returned %d %s\n",
- size, ret, errmsg);
+ ret =
+ dataasciichk("this is a test of the my string", buffer, size, 0,
+ &errmsg);
+ printf
+ ("dataasciichk(\"this is a test of the my string\", buffer, %d, 0, &errmsg) returned %d %s\n",
+ size, ret, errmsg);
- if (ret == -1)
- printf("\tPASS return value is -1 as expected\n");
- else
- printf("\tFAIL return value is %d, expected -1\n", ret);
+ if (ret == -1)
+ printf("\tPASS return value is -1 as expected\n");
+ else
+ printf("\tFAIL return value is %d, expected -1\n", ret);
- ret=dataasciichk("this is a test of the my string", &buffer[1], size-1, 1, &errmsg);
- printf("dataasciichk(\"this is a test of the my string\", &buffer[1], %d, 1, &errmsg) returned %d %s\n",
- size-1, ret, errmsg);
+ ret =
+ dataasciichk("this is a test of the my string", &buffer[1],
+ size - 1, 1, &errmsg);
+ printf
+ ("dataasciichk(\"this is a test of the my string\", &buffer[1], %d, 1, &errmsg) returned %d %s\n",
+ size - 1, ret, errmsg);
- if (ret == -1)
- printf("\tPASS return value is -1 as expected\n");
- else
- printf("\tFAIL return value is %d, expected -1\n", ret);
+ if (ret == -1)
+ printf("\tPASS return value is -1 as expected\n");
+ else
+ printf("\tFAIL return value is %d, expected -1\n", ret);
- buffer[25]= 0x0;
- printf("changing char 25\n");
+ buffer[25] = 0x0;
+ printf("changing char 25\n");
- ret=dataasciichk("this is a test of the my string", &buffer[1], size-1, 1, &errmsg);
- printf("dataasciichk(\"this is a test of the my string\", &buffer[1], %d, 1, &errmsg) returned %d %s\n",
- size-1, ret, errmsg);
+ ret =
+ dataasciichk("this is a test of the my string", &buffer[1],
+ size - 1, 1, &errmsg);
+ printf
+ ("dataasciichk(\"this is a test of the my string\", &buffer[1], %d, 1, &errmsg) returned %d %s\n",
+ size - 1, ret, errmsg);
- if (ret == 25)
- printf("\tPASS return value is 25 as expected\n");
- else
- printf("\tFAIL return value is %d, expected 25\n", ret);
+ if (ret == 25)
+ printf("\tPASS return value is 25 as expected\n");
+ else
+ printf("\tFAIL return value is %d, expected 25\n", ret);
- exit(0);
+ exit(0);
}
#endif
diff --git a/lib/databin.c b/lib/databin.c
index 3a888f7..f4f4f1c 100644
--- a/lib/databin.c
+++ b/lib/databin.c
@@ -31,8 +31,8 @@
*/
#include <stdio.h>
#include <sys/param.h>
-#include <string.h> /* memset */
-#include <stdlib.h> /* rand */
+#include <string.h> /* memset */
+#include <stdlib.h> /* rand */
#include "databin.h"
#if UNIT_TEST
@@ -41,45 +41,43 @@
static char Errmsg[80];
-void
-databingen (mode, buffer, bsize, offset)
-int mode; /* either a, c, r, o, z or C */
-char *buffer; /* buffer pointer */
-int bsize; /* size of buffer */
-int offset; /* offset into the file where buffer starts */
+void databingen(mode, buffer, bsize, offset)
+int mode; /* either a, c, r, o, z or C */
+char *buffer; /* buffer pointer */
+int bsize; /* size of buffer */
+int offset; /* offset into the file where buffer starts */
{
-int ind;
+ int ind;
- switch (mode)
- {
- default:
- case 'a': /* alternating bit pattern */
- memset(buffer,0x55,bsize);
- break;
+ switch (mode) {
+ default:
+ case 'a': /* alternating bit pattern */
+ memset(buffer, 0x55, bsize);
+ break;
- case 'c': /* checkerboard pattern */
- memset(buffer,0xf0,bsize);
- break;
+ case 'c': /* checkerboard pattern */
+ memset(buffer, 0xf0, bsize);
+ break;
- case 'C': /* */
- for (ind=0;ind< bsize;ind++) {
- buffer[ind] = ((offset+ind)%8 & 0177);
+ case 'C': /* */
+ for (ind = 0; ind < bsize; ind++) {
+ buffer[ind] = ((offset + ind) % 8 & 0177);
}
break;
case 'o':
- memset(buffer,0xff,bsize);
+ memset(buffer, 0xff, bsize);
break;
case 'z':
- memset(buffer,0x0,bsize);
+ memset(buffer, 0x0, bsize);
break;
- case 'r': /* random */
- for (ind=0;ind< bsize;ind++) {
- buffer[ind] = (rand () & 0177) | 0100;
+ case 'r': /* random */
+ for (ind = 0; ind < bsize; ind++) {
+ buffer[ind] = (rand() & 0177) | 0100;
}
- }
+ }
}
/***********************************************************************
@@ -88,74 +86,73 @@
* >= 0 : error at byte offset into the file, offset+buffer[0-(bsize-1)]
* < 0 : no error
***********************************************************************/
-int
-databinchk(mode, buffer, bsize, offset, errmsg)
-int mode; /* either a, c, r, z, o, or C */
-char *buffer; /* buffer pointer */
-int bsize; /* size of buffer */
-int offset; /* offset into the file where buffer starts */
+int databinchk(mode, buffer, bsize, offset, errmsg)
+int mode; /* either a, c, r, z, o, or C */
+char *buffer; /* buffer pointer */
+int bsize; /* size of buffer */
+int offset; /* offset into the file where buffer starts */
char **errmsg;
{
- int cnt;
- unsigned char *chr;
- long expbits;
- long actbits;
+ int cnt;
+ unsigned char *chr;
+ long expbits;
+ long actbits;
- chr = (unsigned char *) buffer;
+ chr = (unsigned char *)buffer;
if (errmsg != NULL) {
- *errmsg = Errmsg;
+ *errmsg = Errmsg;
}
- switch (mode)
- {
- default:
- case 'a': /* alternating bit pattern */
- expbits=0x55;
- break;
+ switch (mode) {
+ default:
+ case 'a': /* alternating bit pattern */
+ expbits = 0x55;
+ break;
- case 'c': /* checkerboard pattern */
- expbits=0xf0;
- break;
+ case 'c': /* checkerboard pattern */
+ expbits = 0xf0;
+ break;
- case 'C': /* counting pattern */
- for (cnt=0;cnt< bsize;cnt++) {
- expbits = ((offset+cnt)%8 & 0177);
+ case 'C': /* counting pattern */
+ for (cnt = 0; cnt < bsize; cnt++) {
+ expbits = ((offset + cnt) % 8 & 0177);
- if (buffer[cnt] != expbits) {
- sprintf(Errmsg,
- "data mismatch at offset %d, exp:%#lo, act:%#o",
- offset+cnt, expbits, buffer[cnt]);
- return offset+cnt;
- }
+ if (buffer[cnt] != expbits) {
+ sprintf(Errmsg,
+ "data mismatch at offset %d, exp:%#lo, act:%#o",
+ offset + cnt, expbits, buffer[cnt]);
+ return offset + cnt;
+ }
}
sprintf(Errmsg, "all %d bytes match desired pattern", bsize);
return -1;
case 'o':
- expbits=0xff;
+ expbits = 0xff;
break;
case 'z':
- expbits=0;
+ expbits = 0;
break;
- case 'r':
+ case 'r':
return -1; /* no check can be done for random */
- }
+ }
- for (cnt=0; cnt<bsize; chr++, cnt++) {
- actbits = (long)*chr;
+ for (cnt = 0; cnt < bsize; chr++, cnt++) {
+ actbits = (long)*chr;
- if (actbits != expbits) {
- sprintf(Errmsg, "data mismatch at offset %d, exp:%#lo, act:%#lo",
- offset+cnt, expbits, actbits);
- return offset+cnt;
- }
+ if (actbits != expbits) {
+ sprintf(Errmsg,
+ "data mismatch at offset %d, exp:%#lo, act:%#lo",
+ offset + cnt, expbits, actbits);
+ return offset + cnt;
+ }
}
sprintf(Errmsg, "all %d bytes match desired pattern", bsize);
- return -1; /* all ok */
+ return -1; /* all ok */
}
#if UNIT_TEST
@@ -163,132 +160,130 @@
/***********************************************************************
* main for doing unit testing
***********************************************************************/
-int
-main(ac, ag)
+int main(ac, ag)
int ac;
char **ag;
{
- int size=1023;
- int offset;
- int number;
- unsigned char *buffer;
- int ret;
- char *errmsg;
+ int size = 1023;
+ int offset;
+ int number;
+ unsigned char *buffer;
+ int ret;
+ char *errmsg;
- if ((buffer=(unsigned char *)malloc(size)) == NULL) {
- perror("malloc");
- exit(2);
- }
+ if ((buffer = (unsigned char *)malloc(size)) == NULL) {
+ perror("malloc");
+ exit(2);
+ }
+ printf("***** for a ****************************\n");
+ databingen('a', buffer, size, 0);
+ printf("databingen('a', buffer, %d, 0)\n", size);
-printf("***** for a ****************************\n");
- databingen('a', buffer, size, 0);
- printf("databingen('a', buffer, %d, 0)\n", size);
+ ret = databinchk('a', buffer, size, 0, &errmsg);
+ printf("databinchk('a', buffer, %d, 0, &errmsg) returned %d: %s\n",
+ size, ret, errmsg);
+ if (ret == -1)
+ printf("\tPASS return value of -1 as expected\n");
+ else
+ printf("\tFAIL return value %d, expected -1\n", ret);
- ret=databinchk('a', buffer, size, 0, &errmsg);
- printf("databinchk('a', buffer, %d, 0, &errmsg) returned %d: %s\n",
- size, ret, errmsg);
- if (ret == -1)
- printf("\tPASS return value of -1 as expected\n");
- else
- printf("\tFAIL return value %d, expected -1\n", ret);
+ offset = 232400;
+ ret = databinchk('a', &buffer[1], size - 1, offset, &errmsg);
+ printf("databinchk('a', &buffer[1], %d, %d, &errmsg) returned %d: %s\n",
+ size, offset, ret, errmsg);
+ if (ret == -1)
+ printf("\tPASS return value of -1 as expected\n");
+ else
+ printf("\tFAIL return value %d, expected -1\n", ret);
- offset=232400;
- ret=databinchk('a', &buffer[1], size-1, offset, &errmsg);
- printf("databinchk('a', &buffer[1], %d, %d, &errmsg) returned %d: %s\n",
- size, offset, ret, errmsg);
- if (ret == -1)
- printf("\tPASS return value of -1 as expected\n");
- else
- printf("\tFAIL return value %d, expected -1\n", ret);
+ buffer[15] = 0x0;
+ printf("changing char 15 (offset (%d+15) = %d) to 0x0\n", offset,
+ offset + 15);
+ number = offset + 15;
- buffer[15]= 0x0;
- printf("changing char 15 (offset (%d+15) = %d) to 0x0\n", offset, offset+15);
- number=offset+15;
+ ret = databinchk('a', &buffer[1], size - 1, offset + 1, &errmsg);
+ printf("databinchk('a', &buffer[1], %d, %d, &errmsg) returned %d: %s\n",
+ size - 1, offset + 1, ret, errmsg);
+ if (ret == number)
+ printf("\tPASS return value of %d as expected\n", number);
+ else
+ printf("\tFAIL return value %d, expected %d\n", ret, number);
- ret=databinchk('a', &buffer[1], size-1, offset+1, &errmsg);
- printf("databinchk('a', &buffer[1], %d, %d, &errmsg) returned %d: %s\n",
- size-1, offset+1, ret, errmsg);
- if (ret == number)
- printf("\tPASS return value of %d as expected\n", number);
- else
- printf("\tFAIL return value %d, expected %d\n", ret, number);
+ printf("***** for c ****************************\n");
+ databingen('c', buffer, size, 0);
+ printf("databingen('c', buffer, %d, 0)\n", size);
+ ret = databinchk('c', buffer, size, 0, &errmsg);
+ printf("databinchk('c', buffer, %d, 0, &errmsg) returned %d: %s\n",
+ size, ret, errmsg);
+ if (ret == -1)
+ printf("\tPASS return value of -1 as expected\n");
+ else
+ printf("\tFAIL return value %d, expected -1\n", ret);
+ offset = 232400;
+ ret = databinchk('c', &buffer[1], size - 1, offset, &errmsg);
+ printf("databinchk('c', &buffer[1], %d, %d, &errmsg) returned %d: %s\n",
+ size, offset, ret, errmsg);
+ if (ret == -1)
+ printf("\tPASS return value of -1 as expected\n");
+ else
+ printf("\tFAIL return value %d, expected -1\n", ret);
-printf("***** for c ****************************\n");
- databingen('c', buffer, size, 0);
- printf("databingen('c', buffer, %d, 0)\n", size);
+ buffer[15] = 0x0;
+ printf("changing char 15 (offset (%d+15) = %d) to 0x0\n", offset,
+ offset + 15);
+ number = offset + 15;
- ret=databinchk('c', buffer, size, 0, &errmsg);
- printf("databinchk('c', buffer, %d, 0, &errmsg) returned %d: %s\n",
- size, ret, errmsg);
- if (ret == -1)
- printf("\tPASS return value of -1 as expected\n");
- else
- printf("\tFAIL return value %d, expected -1\n", ret);
+ ret = databinchk('c', &buffer[1], size - 1, offset + 1, &errmsg);
+ printf("databinchk('c', &buffer[1], %d, %d, &errmsg) returned %d: %s\n",
+ size - 1, offset + 1, ret, errmsg);
+ if (ret == number)
+ printf("\tPASS return value of %d as expected\n", number);
+ else
+ printf("\tFAIL return value %d, expected %d\n", ret, number);
- offset=232400;
- ret=databinchk('c', &buffer[1], size-1, offset, &errmsg);
- printf("databinchk('c', &buffer[1], %d, %d, &errmsg) returned %d: %s\n",
- size, offset, ret, errmsg);
- if (ret == -1)
- printf("\tPASS return value of -1 as expected\n");
- else
- printf("\tFAIL return value %d, expected -1\n", ret);
+ printf("***** for C ****************************\n");
- buffer[15]= 0x0;
- printf("changing char 15 (offset (%d+15) = %d) to 0x0\n", offset, offset+15);
- number=offset+15;
+ databingen('C', buffer, size, 0);
+ printf("databingen('C', buffer, %d, 0)\n", size);
- ret=databinchk('c', &buffer[1], size-1, offset+1, &errmsg);
- printf("databinchk('c', &buffer[1], %d, %d, &errmsg) returned %d: %s\n",
- size-1, offset+1, ret, errmsg);
- if (ret == number)
- printf("\tPASS return value of %d as expected\n", number);
- else
- printf("\tFAIL return value %d, expected %d\n", ret, number);
+ ret = databinchk('C', buffer, size, 0, &errmsg);
+ printf("databinchk('C', buffer, %d, 0, &errmsg) returned %d: %s\n",
+ size, ret, errmsg);
+ if (ret == -1)
+ printf("\tPASS return value of -1 as expected\n");
+ else
+ printf("\tFAIL return value %d, expected -1\n", ret);
-printf("***** for C ****************************\n");
+ offset = 18;
+ ret = databinchk('C', &buffer[18], size - 18, 18, &errmsg);
+ printf
+ ("databinchk('C', &buffer[18], %d, 18, &errmsg) returned %d: %s\n",
+ size - 18, ret, errmsg);
+ if (ret == -1)
+ printf("\tPASS return value of -1 as expected\n");
+ else
+ printf("\tFAIL return value %d, expected -1\n", ret);
- databingen('C', buffer, size, 0);
- printf("databingen('C', buffer, %d, 0)\n", size);
+ buffer[20] = 0x0;
+ buffer[21] = 0x0;
+ printf("changing char 20 and 21 to 0x0 (offset %d and %d)\n", 20, 21);
- ret=databinchk('C', buffer, size, 0, &errmsg);
- printf("databinchk('C', buffer, %d, 0, &errmsg) returned %d: %s\n",
- size, ret, errmsg);
- if (ret == -1)
- printf("\tPASS return value of -1 as expected\n");
- else
- printf("\tFAIL return value %d, expected -1\n", ret);
+ ret = databinchk('C', &buffer[18], size - 18, 18, &errmsg);
+ printf
+ ("databinchk('C', &buffer[18], %d, 18, &errmsg) returned %d: %s\n",
+ size - 18, ret, errmsg);
- offset=18;
- ret=databinchk('C', &buffer[18], size-18, 18, &errmsg);
- printf("databinchk('C', &buffer[18], %d, 18, &errmsg) returned %d: %s\n",
- size-18, ret, errmsg);
- if (ret == -1)
- printf("\tPASS return value of -1 as expected\n");
- else
- printf("\tFAIL return value %d, expected -1\n", ret);
+ if (ret == 20 || ret == 21)
+ printf("\tPASS return value of %d or %d as expected\n", 20, 21);
+ else
+ printf("\tFAIL return value %d, expected %d or %d\n", ret,
+ 20, 21);
- buffer[20]= 0x0;
- buffer[21]= 0x0;
- printf("changing char 20 and 21 to 0x0 (offset %d and %d)\n", 20,
- 21);
-
- ret=databinchk('C', &buffer[18], size-18, 18, &errmsg);
- printf("databinchk('C', &buffer[18], %d, 18, &errmsg) returned %d: %s\n",
- size-18, ret, errmsg);
-
- if (ret == 20 || ret == 21)
- printf("\tPASS return value of %d or %d as expected\n",
- 20, 21);
- else
- printf("\tFAIL return value %d, expected %d or %d\n", ret,
- 20, 21 );
-
- exit(0);
+ exit(0);
}
diff --git a/lib/datapid.c b/lib/datapid.c
index 9f34a61..23164d3 100644
--- a/lib/datapid.c
+++ b/lib/datapid.c
@@ -42,7 +42,6 @@
________________________________________________________________
< pid >< offset in file of this word >< pid >
-
8 bits to a bytes == character
NBPW 8
************/
@@ -64,7 +63,7 @@
#define LOWBITS(WRD, bits) ( (-1 >> (64-bits)) & WRD)
****/
-#define NBPBYTE 8 /* number bits per byte */
+#define NBPBYTE 8 /* number bits per byte */
#ifndef DEBUG
#define DEBUG 0
@@ -82,8 +81,7 @@
* thus, offset 16 is the start of the second full word
* Thus, offset 8 is in middle of word 1
***********************************************************************/
-int
-datapidgen(pid, buffer, bsize, offset)
+int datapidgen(pid, buffer, bsize, offset)
int pid;
char *buffer;
int bsize;
@@ -91,83 +89,90 @@
{
#if CRAY
- int cnt;
- int tmp;
- char *chr;
- long *wptr;
- long word;
- int woff; /* file offset for the word */
- int boff; /* buffer offset or index */
- int num_full_words;
+ int cnt;
+ int tmp;
+ char *chr;
+ long *wptr;
+ long word;
+ int woff; /* file offset for the word */
+ int boff; /* buffer offset or index */
+ int num_full_words;
- num_full_words = bsize/NBPW;
- boff = 0;
+ num_full_words = bsize / NBPW;
+ boff = 0;
- if (cnt=(offset % NBPW)) { /* partial word */
+ if (cnt = (offset % NBPW)) { /* partial word */
- woff = offset - cnt;
+ woff = offset - cnt;
#if DEBUG
-printf("partial at beginning, cnt = %d, woff = %d\n", cnt, woff);
+ printf("partial at beginning, cnt = %d, woff = %d\n", cnt,
+ woff);
#endif
- word = ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) | LOWER16BITS(pid));
+ word =
+ ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) |
+ LOWER16BITS(pid));
- chr = (char *)&word;
+ chr = (char *)&word;
- for (tmp=0; tmp<cnt; tmp++) { /* skip unused bytes */
- chr++;
- }
+ for (tmp = 0; tmp < cnt; tmp++) { /* skip unused bytes */
+ chr++;
+ }
- for (; boff<(NBPW-cnt) && boff<bsize; boff++, chr++) {
- buffer[boff] = *chr;
+ for (; boff < (NBPW - cnt) && boff < bsize; boff++, chr++) {
+ buffer[boff] = *chr;
+ }
}
- }
- /*
- * full words
- */
+ /*
+ * full words
+ */
- num_full_words = (bsize-boff)/NBPW;
+ num_full_words = (bsize - boff) / NBPW;
- woff = offset+boff;
+ woff = offset + boff;
- for (cnt=0; cnt<num_full_words; woff += NBPW, cnt++) {
+ for (cnt = 0; cnt < num_full_words; woff += NBPW, cnt++) {
- word = ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) | LOWER16BITS(pid));
+ word =
+ ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) |
+ LOWER16BITS(pid));
- chr = (char *)&word;
- for (tmp=0; tmp<NBPW; tmp++, chr++) {
- buffer[boff++] = *chr;
- }
+ chr = (char *)&word;
+ for (tmp = 0; tmp < NBPW; tmp++, chr++) {
+ buffer[boff++] = *chr;
+ }
/****** Only if wptr is a word ellined
wptr = (long *)&buffer[boff];
*wptr = word;
boff += NBPW;
*****/
- }
-
- /*
- * partial word at end of buffer
- */
-
- if (cnt=((bsize-boff) % NBPW)) {
-#if DEBUG
-printf("partial at end\n");
-#endif
- word = ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) | LOWER16BITS(pid));
-
- chr = (char *)&word;
-
- for (tmp=0; tmp<cnt && boff<bsize; tmp++, chr++) {
- buffer[boff++] = *chr;
}
- }
- return bsize;
+ /*
+ * partial word at end of buffer
+ */
+
+ if (cnt = ((bsize - boff) % NBPW)) {
+#if DEBUG
+ printf("partial at end\n");
+#endif
+ word =
+ ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) |
+ LOWER16BITS(pid));
+
+ chr = (char *)&word;
+
+ for (tmp = 0; tmp < cnt && boff < bsize; tmp++, chr++) {
+ buffer[boff++] = *chr;
+ }
+ }
+
+ return bsize;
#else
- return -1; /* not support on non-64 bits word machines */
+ return -1; /* not support on non-64 bits word machines */
#endif
@@ -177,8 +182,7 @@
*
*
***********************************************************************/
-int
-datapidchk(pid, buffer, bsize, offset, errmsg)
+int datapidchk(pid, buffer, bsize, offset, errmsg)
int pid;
char *buffer;
int bsize;
@@ -187,63 +191,67 @@
{
#if CRAY
- int cnt;
- int tmp;
- char *chr;
- long *wptr;
- long word;
- int woff; /* file offset for the word */
- int boff; /* buffer offset or index */
- int num_full_words;
+ int cnt;
+ int tmp;
+ char *chr;
+ long *wptr;
+ long word;
+ int woff; /* file offset for the word */
+ int boff; /* buffer offset or index */
+ int num_full_words;
-
- if (errmsg != NULL) {
- *errmsg = Errmsg;
- }
-
-
- num_full_words = bsize/NBPW;
- boff = 0;
-
- if (cnt=(offset % NBPW)) { /* partial word */
- woff = offset - cnt;
- word = ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) | LOWER16BITS(pid));
-
- chr = (char *)&word;
-
- for (tmp=0; tmp<cnt; tmp++) { /* skip unused bytes */
- chr++;
- }
-
- for (; boff<(NBPW-cnt) && boff<bsize; boff++, chr++) {
- if (buffer[boff] != *chr) {
- sprintf(Errmsg, "Data mismatch at offset %d, exp:%#o, act:%#o",
- offset+boff, *chr, buffer[boff]);
- return offset+boff;
- }
+ if (errmsg != NULL) {
+ *errmsg = Errmsg;
}
- }
- /*
- * full words
- */
+ num_full_words = bsize / NBPW;
+ boff = 0;
- num_full_words = (bsize-boff)/NBPW;
+ if (cnt = (offset % NBPW)) { /* partial word */
+ woff = offset - cnt;
+ word =
+ ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) |
+ LOWER16BITS(pid));
- woff = offset+boff;
+ chr = (char *)&word;
- for (cnt=0; cnt<num_full_words; woff += NBPW, cnt++) {
- word = ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) | LOWER16BITS(pid));
+ for (tmp = 0; tmp < cnt; tmp++) { /* skip unused bytes */
+ chr++;
+ }
- chr = (char *)&word;
- for (tmp=0; tmp<NBPW; tmp++, boff++, chr++) {
- if (buffer[boff] != *chr) {
- sprintf(Errmsg, "Data mismatch at offset %d, exp:%#o, act:%#o",
- woff, *chr, buffer[boff]);
- return woff;
- }
+ for (; boff < (NBPW - cnt) && boff < bsize; boff++, chr++) {
+ if (buffer[boff] != *chr) {
+ sprintf(Errmsg,
+ "Data mismatch at offset %d, exp:%#o, act:%#o",
+ offset + boff, *chr, buffer[boff]);
+ return offset + boff;
+ }
+ }
}
+ /*
+ * full words
+ */
+
+ num_full_words = (bsize - boff) / NBPW;
+
+ woff = offset + boff;
+
+ for (cnt = 0; cnt < num_full_words; woff += NBPW, cnt++) {
+ word =
+ ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) |
+ LOWER16BITS(pid));
+
+ chr = (char *)&word;
+ for (tmp = 0; tmp < NBPW; tmp++, boff++, chr++) {
+ if (buffer[boff] != *chr) {
+ sprintf(Errmsg,
+ "Data mismatch at offset %d, exp:%#o, act:%#o",
+ woff, *chr, buffer[boff]);
+ return woff;
+ }
+ }
+
/****** only if a word elined
wptr = (long *)&buffer[boff];
if (*wptr != word) {
@@ -253,121 +261,122 @@
}
boff += NBPW;
******/
- }
-
- /*
- * partial word at end of buffer
- */
-
- if (cnt=((bsize-boff) % NBPW)) {
-#if DEBUG
-printf("partial at end\n");
-#endif
- word = ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) | LOWER16BITS(pid));
-
- chr = (char *)&word;
-
-
- for (tmp=0; tmp<cnt && boff<bsize; boff++, tmp++, chr++) {
- if (buffer[boff] != *chr) {
- sprintf(Errmsg, "Data mismatch at offset %d, exp:%#o, act:%#o",
- offset+boff, *chr, buffer[boff]);
- return offset+boff;
- }
}
- }
- sprintf(Errmsg, "all %d bytes match desired pattern", bsize);
- return -1; /* buffer is ok */
+ /*
+ * partial word at end of buffer
+ */
+
+ if (cnt = ((bsize - boff) % NBPW)) {
+#if DEBUG
+ printf("partial at end\n");
+#endif
+ word =
+ ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) |
+ LOWER16BITS(pid));
+
+ chr = (char *)&word;
+
+ for (tmp = 0; tmp < cnt && boff < bsize; boff++, tmp++, chr++) {
+ if (buffer[boff] != *chr) {
+ sprintf(Errmsg,
+ "Data mismatch at offset %d, exp:%#o, act:%#o",
+ offset + boff, *chr, buffer[boff]);
+ return offset + boff;
+ }
+ }
+ }
+
+ sprintf(Errmsg, "all %d bytes match desired pattern", bsize);
+ return -1; /* buffer is ok */
#else
- if (errmsg != NULL) {
- *errmsg = Errmsg;
- }
- sprintf(Errmsg, "Not supported on this OS.");
- return 0;
+ if (errmsg != NULL) {
+ *errmsg = Errmsg;
+ }
+ sprintf(Errmsg, "Not supported on this OS.");
+ return 0;
#endif
-
-} /* end of datapidchk */
+} /* end of datapidchk */
#if UNIT_TEST
/***********************************************************************
* main for doing unit testing
***********************************************************************/
-int
-main(ac, ag)
+int main(ac, ag)
int ac;
char **ag;
{
-int size=1234;
-char *buffer;
-int ret;
-char *errmsg;
+ int size = 1234;
+ char *buffer;
+ int ret;
+ char *errmsg;
- if ((buffer=(char *)malloc(size)) == NULL) {
- perror("malloc");
- exit(2);
- }
+ if ((buffer = (char *)malloc(size)) == NULL) {
+ perror("malloc");
+ exit(2);
+ }
-
- datapidgen(-1, buffer, size, 3);
+ datapidgen(-1, buffer, size, 3);
/***
fwrite(buffer, size, 1, stdout);
fwrite("\n", 1, 1, stdout);
****/
- printf("datapidgen(-1, buffer, size, 3)\n");
+ printf("datapidgen(-1, buffer, size, 3)\n");
- ret=datapidchk(-1, buffer, size, 3, &errmsg);
- printf("datapidchk(-1, buffer, %d, 3, &errmsg) returned %d %s\n",
- size, ret, errmsg);
- ret=datapidchk(-1, &buffer[1], size-1, 4, &errmsg);
- printf("datapidchk(-1, &buffer[1], %d, 4, &errmsg) returned %d %s\n",
- size-1, ret, errmsg);
+ ret = datapidchk(-1, buffer, size, 3, &errmsg);
+ printf("datapidchk(-1, buffer, %d, 3, &errmsg) returned %d %s\n",
+ size, ret, errmsg);
+ ret = datapidchk(-1, &buffer[1], size - 1, 4, &errmsg);
+ printf("datapidchk(-1, &buffer[1], %d, 4, &errmsg) returned %d %s\n",
+ size - 1, ret, errmsg);
- buffer[25]= 0x0;
- buffer[26]= 0x0;
- buffer[27]= 0x0;
- buffer[28]= 0x0;
- printf("changing char 25-28\n");
+ buffer[25] = 0x0;
+ buffer[26] = 0x0;
+ buffer[27] = 0x0;
+ buffer[28] = 0x0;
+ printf("changing char 25-28\n");
- ret=datapidchk(-1, &buffer[1], size-1, 4, &errmsg);
- printf("datapidchk(-1, &buffer[1], %d, 4, &errmsg) returned %d %s\n",
- size-1, ret, errmsg);
+ ret = datapidchk(-1, &buffer[1], size - 1, 4, &errmsg);
+ printf("datapidchk(-1, &buffer[1], %d, 4, &errmsg) returned %d %s\n",
+ size - 1, ret, errmsg);
-printf("------------------------------------------\n");
+ printf("------------------------------------------\n");
- datapidgen(getpid(), buffer, size, 5);
+ datapidgen(getpid(), buffer, size, 5);
/*******
fwrite(buffer, size, 1, stdout);
fwrite("\n", 1, 1, stdout);
******/
- printf("\ndatapidgen(getpid(), buffer, size, 5)\n");
+ printf("\ndatapidgen(getpid(), buffer, size, 5)\n");
- ret=datapidchk(getpid(), buffer, size, 5, &errmsg);
- printf("datapidchk(getpid(), buffer, %d, 5, &errmsg) returned %d %s\n",
- size, ret, errmsg);
+ ret = datapidchk(getpid(), buffer, size, 5, &errmsg);
+ printf("datapidchk(getpid(), buffer, %d, 5, &errmsg) returned %d %s\n",
+ size, ret, errmsg);
- ret=datapidchk(getpid(), &buffer[1], size-1, 6, &errmsg);
- printf("datapidchk(getpid(), &buffer[1], %d, 6, &errmsg) returned %d %s\n",
- size-1, ret, errmsg);
+ ret = datapidchk(getpid(), &buffer[1], size - 1, 6, &errmsg);
+ printf
+ ("datapidchk(getpid(), &buffer[1], %d, 6, &errmsg) returned %d %s\n",
+ size - 1, ret, errmsg);
- buffer[25]= 0x0;
- printf("changing char 25\n");
+ buffer[25] = 0x0;
+ printf("changing char 25\n");
- ret=datapidchk(getpid(), &buffer[1], size-1, 6, &errmsg);
- printf("datapidchk(getpid(), &buffer[1], %d, 6, &errmsg) returned %d %s\n",
- size-1, ret, errmsg);
+ ret = datapidchk(getpid(), &buffer[1], size - 1, 6, &errmsg);
+ printf
+ ("datapidchk(getpid(), &buffer[1], %d, 6, &errmsg) returned %d %s\n",
+ size - 1, ret, errmsg);
- exit(0);
+ exit(0);
}
#endif
diff --git a/lib/file_lock.c b/lib/file_lock.c
index d979552..52c8947 100644
--- a/lib/file_lock.c
+++ b/lib/file_lock.c
@@ -38,10 +38,9 @@
#include <stdio.h>
#include <errno.h>
#include <sys/sysmacros.h>
-#include <string.h> /* memset, strerror */
+#include <string.h> /* memset, strerror */
#include "file_lock.h"
-
#ifndef EFSEXCLWR
#define EFSEXCLWR 503
#endif
@@ -59,150 +58,149 @@
* Test interface to the fcntl system call.
* It will loop if the LOCK_NB flags is NOT set.
***********************************************************************/
-int
-file_lock(fd, flags, errormsg)
+int file_lock(fd, flags, errormsg)
int fd;
int flags;
char **errormsg;
{
- register int cmd, ret;
- struct flock flocks;
+ register int cmd, ret;
+ struct flock flocks;
- memset(&flocks, 0, sizeof(struct flock));
+ memset(&flocks, 0, sizeof(struct flock));
- if (flags&LOCK_NB)
- cmd = F_SETLK;
- else
- cmd = F_SETLKW;
+ if (flags & LOCK_NB)
+ cmd = F_SETLK;
+ else
+ cmd = F_SETLKW;
- flocks.l_whence = 0;
- flocks.l_start = 0;
- flocks.l_len = 0;
+ flocks.l_whence = 0;
+ flocks.l_start = 0;
+ flocks.l_len = 0;
- if (flags&LOCK_UN)
- flocks.l_type = F_UNLCK;
- else if (flags&LOCK_EX)
- flocks.l_type = F_WRLCK;
- else if (flags&LOCK_SH)
- flocks.l_type = F_RDLCK;
- else {
- errno = EINVAL;
- if (errormsg != NULL) {
- sprintf(errmsg,
- "Programmer error, called file_lock with in valid flags\n");
- *errormsg = errmsg;
- }
- return -1;
- }
+ if (flags & LOCK_UN)
+ flocks.l_type = F_UNLCK;
+ else if (flags & LOCK_EX)
+ flocks.l_type = F_WRLCK;
+ else if (flags & LOCK_SH)
+ flocks.l_type = F_RDLCK;
+ else {
+ errno = EINVAL;
+ if (errormsg != NULL) {
+ sprintf(errmsg,
+ "Programmer error, called file_lock with in valid flags\n");
+ *errormsg = errmsg;
+ }
+ return -1;
+ }
sprintf(Fl_syscall_str,
- "fcntl(%d, %d, &flocks): type:%d whence:%d, start:%lld len:%lld\n",
- fd, cmd, flocks.l_type, flocks.l_whence,
+ "fcntl(%d, %d, &flocks): type:%d whence:%d, start:%lld len:%lld\n",
+ fd, cmd, flocks.l_type, flocks.l_whence,
(long long)flocks.l_start, (long long)flocks.l_len);
while (1) {
- ret = fcntl(fd, cmd, &flocks);
+ ret = fcntl(fd, cmd, &flocks);
- if (ret < 0) {
- if (cmd == F_SETLK)
- switch (errno) {
- /* these errors are okay */
- case EACCES: /* Permission denied */
- case EINTR: /* interrupted system call */
+ if (ret < 0) {
+ if (cmd == F_SETLK)
+ switch (errno) {
+ /* these errors are okay */
+ case EACCES: /* Permission denied */
+ case EINTR: /* interrupted system call */
#ifdef EFILESH
- case EFILESH: /* file shared */
+ case EFILESH: /* file shared */
#endif
- case EFSEXCLWR: /* File is write protected */
- continue; /* retry getting lock */
- }
- if (errormsg != NULL) {
- sprintf(errmsg, "fcntl(%d, %d, &flocks): errno:%d %s\n",
- fd, cmd, errno, strerror(errno));
- *errormsg = errmsg;
- }
- return -1;
- }
- break;
+ case EFSEXCLWR: /* File is write protected */
+ continue; /* retry getting lock */
+ }
+ if (errormsg != NULL) {
+ sprintf(errmsg,
+ "fcntl(%d, %d, &flocks): errno:%d %s\n",
+ fd, cmd, errno, strerror(errno));
+ *errormsg = errmsg;
+ }
+ return -1;
+ }
+ break;
}
- return ret;
+ return ret;
-} /* end of file_lock */
+} /* end of file_lock */
/***********************************************************************
*
* Test interface to the fcntl system call.
* It will loop if the LOCK_NB flags is NOT set.
***********************************************************************/
-int
-record_lock(fd, flags, start, len, errormsg)
+int record_lock(fd, flags, start, len, errormsg)
int fd;
int flags;
int start;
int len;
char **errormsg;
{
- register int cmd, ret;
- struct flock flocks;
+ register int cmd, ret;
+ struct flock flocks;
- memset(&flocks, 0, sizeof(struct flock));
+ memset(&flocks, 0, sizeof(struct flock));
- if (flags&LOCK_NB)
- cmd = F_SETLK;
- else
- cmd = F_SETLKW;
+ if (flags & LOCK_NB)
+ cmd = F_SETLK;
+ else
+ cmd = F_SETLKW;
- flocks.l_whence = 0;
- flocks.l_start = start;
- flocks.l_len = len;
+ flocks.l_whence = 0;
+ flocks.l_start = start;
+ flocks.l_len = len;
- if (flags&LOCK_UN)
- flocks.l_type = F_UNLCK;
- else if (flags&LOCK_EX)
- flocks.l_type = F_WRLCK;
- else if (flags&LOCK_SH)
- flocks.l_type = F_RDLCK;
- else {
- errno = EINVAL;
- if (errormsg != NULL) {
- sprintf(errmsg,
- "Programmer error, called record_lock with in valid flags\n");
- *errormsg = errmsg;
- }
- return -1;
- }
+ if (flags & LOCK_UN)
+ flocks.l_type = F_UNLCK;
+ else if (flags & LOCK_EX)
+ flocks.l_type = F_WRLCK;
+ else if (flags & LOCK_SH)
+ flocks.l_type = F_RDLCK;
+ else {
+ errno = EINVAL;
+ if (errormsg != NULL) {
+ sprintf(errmsg,
+ "Programmer error, called record_lock with in valid flags\n");
+ *errormsg = errmsg;
+ }
+ return -1;
+ }
sprintf(Fl_syscall_str,
- "fcntl(%d, %d, &flocks): type:%d whence:%d, start:%lld len:%lld\n",
- fd, cmd, flocks.l_type, flocks.l_whence,
+ "fcntl(%d, %d, &flocks): type:%d whence:%d, start:%lld len:%lld\n",
+ fd, cmd, flocks.l_type, flocks.l_whence,
(long long)flocks.l_start, (long long)flocks.l_len);
while (1) {
- ret = fcntl(fd, cmd, &flocks);
+ ret = fcntl(fd, cmd, &flocks);
- if (ret < 0) {
- if (cmd == F_SETLK)
- switch (errno) {
- /* these errors are okay */
- case EACCES: /* Permission denied */
- case EINTR: /* interrupted system call */
+ if (ret < 0) {
+ if (cmd == F_SETLK)
+ switch (errno) {
+ /* these errors are okay */
+ case EACCES: /* Permission denied */
+ case EINTR: /* interrupted system call */
#ifdef EFILESH
- case EFILESH: /* file shared */
+ case EFILESH: /* file shared */
#endif
- case EFSEXCLWR: /* File is write protected */
- continue; /* retry getting lock */
- }
- if (errormsg != NULL) {
- sprintf(errmsg, "fcntl(%d, %d, &flocks): errno:%d %s\n",
- fd, cmd, errno, strerror(errno));
- *errormsg = errmsg;
- }
- return -1;
- }
- break;
+ case EFSEXCLWR: /* File is write protected */
+ continue; /* retry getting lock */
+ }
+ if (errormsg != NULL) {
+ sprintf(errmsg,
+ "fcntl(%d, %d, &flocks): errno:%d %s\n",
+ fd, cmd, errno, strerror(errno));
+ *errormsg = errmsg;
+ }
+ return -1;
+ }
+ break;
}
- return ret;
+ return ret;
-} /* end of record_lock */
-
+} /* end of record_lock */
diff --git a/lib/forker.c b/lib/forker.c
index 68e90b8..5e6ac48 100644
--- a/lib/forker.c
+++ b/lib/forker.c
@@ -109,13 +109,13 @@
#include <stdio.h>
#include <errno.h>
-#include <unistd.h> /* fork, getpid, sleep */
+#include <unistd.h> /* fork, getpid, sleep */
#include <string.h>
-#include <stdlib.h> /* exit */
+#include <stdlib.h> /* exit */
#include "forker.h"
-int Forker_pids[FORKER_MAX_PIDS]; /* holds pids of forked processes */
-int Forker_npids=0; /* number of entries in Forker_pids */
+int Forker_pids[FORKER_MAX_PIDS]; /* holds pids of forked processes */
+int Forker_npids = 0; /* number of entries in Forker_pids */
/***********************************************************************
*
@@ -127,103 +127,107 @@
* 0 : if fork did not fail
* !0 : if fork failed, the return value will be the errno.
***********************************************************************/
-int
-background(prefix)
+int background(prefix)
char *prefix;
{
- switch (fork()) {
- case -1:
- if (prefix != NULL)
- fprintf(stderr, "%s: In %s background(), fork() failed, errno:%d %s\n",
- prefix, __FILE__, errno, strerror(errno));
- exit(errno);
+ switch (fork()) {
+ case -1:
+ if (prefix != NULL)
+ fprintf(stderr,
+ "%s: In %s background(), fork() failed, errno:%d %s\n",
+ prefix, __FILE__, errno, strerror(errno));
+ exit(errno);
- case 0: /* child process */
- break;
+ case 0: /* child process */
+ break;
- default:
- exit(0);
- }
+ default:
+ exit(0);
+ }
- return 0;
+ return 0;
-} /* end of background */
+} /* end of background */
/***********************************************************************
* Forker will fork ncopies-1 copies of self.
*
***********************************************************************/
-int
-forker(ncopies, mode, prefix)
+int forker(ncopies, mode, prefix)
int ncopies;
-int mode; /* 0 - all childern of parent, 1 - only 1 direct child */
-char *prefix; /* if ! NULL, an message will be printed to stderr */
+int mode; /* 0 - all childern of parent, 1 - only 1 direct child */
+char *prefix; /* if ! NULL, an message will be printed to stderr */
/* if fork fails. The prefix (program name) will */
- /* preceed the message */
+ /* preceed the message */
{
- int cnt;
- int pid;
- static int ind = 0;
+ int cnt;
+ int pid;
+ static int ind = 0;
- Forker_pids[ind]=0;
+ Forker_pids[ind] = 0;
- for (cnt=1; cnt < ncopies; cnt++) {
+ for (cnt = 1; cnt < ncopies; cnt++) {
- switch ( mode ) {
- case 1 : /* only 1 direct child */
- if ((pid = fork()) == -1) {
- if (prefix != NULL)
- fprintf(stderr, "%s: %s,forker(): fork() failed, errno:%d %s\n",
- prefix, __FILE__, errno, strerror(errno));
- return 0;
- }
- Forker_npids++;
+ switch (mode) {
+ case 1: /* only 1 direct child */
+ if ((pid = fork()) == -1) {
+ if (prefix != NULL)
+ fprintf(stderr,
+ "%s: %s,forker(): fork() failed, errno:%d %s\n",
+ prefix, __FILE__, errno,
+ strerror(errno));
+ return 0;
+ }
+ Forker_npids++;
- switch (pid ) {
- case 0: /* child - continues the forking */
+ switch (pid) {
+ case 0: /* child - continues the forking */
- if (Forker_npids < FORKER_MAX_PIDS)
- Forker_pids[Forker_npids-1]=getpid();
- break;
+ if (Forker_npids < FORKER_MAX_PIDS)
+ Forker_pids[Forker_npids - 1] =
+ getpid();
+ break;
- default: /* parent - stop the forking */
- if (Forker_npids < FORKER_MAX_PIDS)
- Forker_pids[Forker_npids-1]=pid;
- return cnt-1;
- }
+ default: /* parent - stop the forking */
+ if (Forker_npids < FORKER_MAX_PIDS)
+ Forker_pids[Forker_npids - 1] = pid;
+ return cnt - 1;
+ }
- break;
+ break;
- default : /* all new processes are childern of parent */
- if ((pid = fork()) == -1) {
- if (prefix != NULL)
- fprintf(stderr, "%s: %s,forker(): fork() failed, errno:%d %s\n",
- prefix, __FILE__, errno, strerror(errno));
- return cnt-1;
- }
- Forker_npids++;
+ default: /* all new processes are childern of parent */
+ if ((pid = fork()) == -1) {
+ if (prefix != NULL)
+ fprintf(stderr,
+ "%s: %s,forker(): fork() failed, errno:%d %s\n",
+ prefix, __FILE__, errno,
+ strerror(errno));
+ return cnt - 1;
+ }
+ Forker_npids++;
- switch (pid ) {
- case 0: /* child - stops the forking */
- if (Forker_npids < FORKER_MAX_PIDS)
- Forker_pids[Forker_npids-1]=getpid();
- return cnt;
+ switch (pid) {
+ case 0: /* child - stops the forking */
+ if (Forker_npids < FORKER_MAX_PIDS)
+ Forker_pids[Forker_npids - 1] =
+ getpid();
+ return cnt;
- default: /* parent - continues the forking */
- if (Forker_npids < FORKER_MAX_PIDS)
- Forker_pids[Forker_npids-1]=pid;
- break;
- }
- break;
+ default: /* parent - continues the forking */
+ if (Forker_npids < FORKER_MAX_PIDS)
+ Forker_pids[Forker_npids - 1] = pid;
+ break;
+ }
+ break;
+ }
}
- }
- if (Forker_npids < FORKER_MAX_PIDS)
- Forker_pids[Forker_npids]=0;
- return cnt-1;
+ if (Forker_npids < FORKER_MAX_PIDS)
+ Forker_pids[Forker_npids] = 0;
+ return cnt - 1;
-} /* end of forker */
-
+} /* end of forker */
#if UNIT_TEST
@@ -232,50 +236,49 @@
* functions.
*/
-int
-main(argc, argv)
+int main(argc, argv)
int argc;
char **argv;
{
- int ncopies=1;
- int mode=0;
- int ret;
- int ind;
+ int ncopies = 1;
+ int mode = 0;
+ int ret;
+ int ind;
- if (argc == 1) {
- printf("Usage: %s ncopies [mode]\n", argv[0]);
- exit(1);
- }
+ if (argc == 1) {
+ printf("Usage: %s ncopies [mode]\n", argv[0]);
+ exit(1);
+ }
- if (sscanf(argv[1], "%i", &ncopies) != 1) {
- printf("%s: ncopies argument must be integer\n", argv[0]);
- exit(1);
- }
+ if (sscanf(argv[1], "%i", &ncopies) != 1) {
+ printf("%s: ncopies argument must be integer\n", argv[0]);
+ exit(1);
+ }
- if (argc == 3)
- if (sscanf(argv[2], "%i", &mode) != 1) {
- printf("%s: mode argument must be integer\n", argv[0]);
- exit(1);
- }
+ if (argc == 3)
+ if (sscanf(argv[2], "%i", &mode) != 1) {
+ printf("%s: mode argument must be integer\n", argv[0]);
+ exit(1);
+ }
- printf("Starting Pid = %d\n", getpid());
- ret=background(argv[0]);
- printf("After background() ret:%d, pid = %d\n", ret, getpid());
+ printf("Starting Pid = %d\n", getpid());
+ ret = background(argv[0]);
+ printf("After background() ret:%d, pid = %d\n", ret, getpid());
- ret=forker(ncopies, mode, argv[0]);
+ ret = forker(ncopies, mode, argv[0]);
- printf("forker(%d, %d, %s) ret:%d, pid = %d, sleeping 30 seconds.\n",
- ncopies, mode, argv[0], ret, getpid());
+ printf("forker(%d, %d, %s) ret:%d, pid = %d, sleeping 30 seconds.\n",
+ ncopies, mode, argv[0], ret, getpid());
- printf("%d My version of Forker_pids[], Forker_npids = %d\n",
- getpid(), Forker_npids);
+ printf("%d My version of Forker_pids[], Forker_npids = %d\n",
+ getpid(), Forker_npids);
- for (ind=0; ind<Forker_npids; ind++) {
- printf("%d ind:%-2d pid:%d\n", getpid(), ind, Forker_pids[ind]);
- }
+ for (ind = 0; ind < Forker_npids; ind++) {
+ printf("%d ind:%-2d pid:%d\n", getpid(), ind, Forker_pids[ind]);
+ }
- sleep(30);
- exit(0);
+ sleep(30);
+ exit(0);
}
-#endif /* UNIT_TEST */
+#endif /* UNIT_TEST */
diff --git a/lib/get_high_address.c b/lib/get_high_address.c
index b357fe0..eed9cf1 100644
--- a/lib/get_high_address.c
+++ b/lib/get_high_address.c
@@ -36,5 +36,5 @@
char *get_high_address(void)
{
- return (char *)sbrk(0) + (4 * getpagesize());
+ return (char *)sbrk(0) + (4 * getpagesize());
}
diff --git a/lib/get_path.c b/lib/get_path.c
index aa78a81..c7bbead 100644
--- a/lib/get_path.c
+++ b/lib/get_path.c
@@ -54,12 +54,11 @@
int tst_get_path(const char *prog_name, char *buf, size_t buf_len)
{
- const char *path = (const char*) getenv("PATH");
+ const char *path = (const char *)getenv("PATH");
const char *start = path;
const char *end;
size_t size, ret;
-
if (path == NULL)
return -1;
@@ -67,7 +66,8 @@
end = strchr(start, ':');
if (end != NULL)
- snprintf(buf, MIN(buf_len, (size_t)(end - start + 1)), "%s", start);
+ snprintf(buf, MIN(buf_len, (size_t) (end - start + 1)),
+ "%s", start);
else
snprintf(buf, buf_len, "%s", start);
@@ -86,9 +86,13 @@
* If there is no '/' ad the end of path from $PATH add it.
*/
if (buf[size - 1] != '/')
- ret = snprintf(buf + size, buf_len - size, "/%s", prog_name);
+ ret =
+ snprintf(buf + size, buf_len - size, "/%s",
+ prog_name);
else
- ret = snprintf(buf + size, buf_len - size, "%s", prog_name);
+ ret =
+ snprintf(buf + size, buf_len - size, "%s",
+ prog_name);
if (buf_len - size > ret && file_exist(buf))
return 0;
diff --git a/lib/libtestsuite.c b/lib/libtestsuite.c
index 698a4eb..713d699 100644
--- a/lib/libtestsuite.c
+++ b/lib/libtestsuite.c
@@ -43,8 +43,7 @@
#include "test.h"
#include "usctest.h"
-struct passwd *
-my_getpwnam(char *name)
+struct passwd *my_getpwnam(char *name)
{
struct passwd *saved_pwent;
struct passwd *pwent;
@@ -57,15 +56,14 @@
*saved_pwent = *pwent;
- return(saved_pwent);
+ return (saved_pwent);
}
-void
-do_file_setup(char *fname)
+void do_file_setup(char *fname)
{
int fd;
- if ((fd = open(fname,O_RDWR|O_CREAT,0700)) == -1) {
+ if ((fd = open(fname, O_RDWR | O_CREAT, 0700)) == -1) {
tst_resm(TBROK, "open(%s, O_RDWR|O_CREAT,0700) Failed, "
"errno=%d : %s", fname, errno, strerror(errno));
}
@@ -84,7 +82,7 @@
p = strrchr(name, '/');
if (p == NULL)
- p = (char *) name;
+ p = (char *)name;
else
p++;
snprintf(pipe_name, 255, "%s/ltp_fifo_%s", P_tmpdir, p);
@@ -118,9 +116,9 @@
int r = 0;
if (fd[0] != -1)
- r = close (fd[0]);
+ r = close(fd[0]);
if (fd[1] != -1)
- r |= close (fd[1]);
+ r |= close(fd[1]);
if (name != NULL) {
generate_pipe_name(name);
@@ -135,11 +133,11 @@
int r;
if (fd[1] != -1) {
- close (fd[1]);
+ close(fd[1]);
fd[1] = -1;
}
- r = read (fd[0], &buf, 1);
+ r = read(fd[0], &buf, 1);
if ((r != 1) || (buf != 'A'))
return -1;
@@ -152,11 +150,11 @@
int r;
if (fd[0] != -1) {
- close (fd[0]);
+ close(fd[0]);
fd[0] = -1;
}
- r = write (fd[1], &buf, 1);
+ r = write(fd[1], &buf, 1);
if (r != 1)
return -1;
diff --git a/lib/mount_utils.c b/lib/mount_utils.c
index 78b0578..03378a9 100644
--- a/lib/mount_utils.c
+++ b/lib/mount_utils.c
@@ -17,8 +17,7 @@
* Returns NULL if the device isn't found, memory couldn't be allocated, or if
* the `block device' isn't a real block device (e.g. nfs mounts, etc).
*/
-char *
-get_block_device(const char *path)
+char *get_block_device(const char *path)
{
char *mnt_dir = NULL, *mnt_fsname = NULL;
@@ -31,8 +30,7 @@
if (path == NULL) {
errno = EINVAL;
} else if ((resolved_path = realpath(path, NULL)) != NULL &&
- (mtab_f = setmntent("/etc/mtab", "r")) != NULL)
- {
+ (mtab_f = setmntent("/etc/mtab", "r")) != NULL) {
do {
@@ -40,23 +38,42 @@
if (entry != NULL) {
- if (!strncmp(entry->mnt_dir, resolved_path, strlen(entry->mnt_dir))) {
+ if (!strncmp
+ (entry->mnt_dir, resolved_path,
+ strlen(entry->mnt_dir))) {
char copy_string = 0;
if (mnt_dir == NULL) {
- mnt_dir = malloc(strlen(entry->mnt_dir)+1);
- mnt_fsname = malloc(strlen(entry->mnt_fsname)+1);
+ mnt_dir =
+ malloc(strlen
+ (entry->mnt_dir) +
+ 1);
+ mnt_fsname =
+ malloc(strlen
+ (entry->mnt_fsname) +
+ 1);
- copy_string = mnt_dir != NULL && mnt_fsname != NULL;
+ copy_string = mnt_dir != NULL
+ && mnt_fsname != NULL;
} else {
- if (!strncmp(entry->mnt_dir, mnt_dir, strlen(entry->mnt_dir))) {
+ if (!strncmp
+ (entry->mnt_dir, mnt_dir,
+ strlen(entry->mnt_dir))) {
- mnt_dir = realloc(mnt_dir, strlen(entry->mnt_dir));
- mnt_fsname = realloc(mnt_fsname, strlen(entry->mnt_fsname));
+ mnt_dir =
+ realloc(mnt_dir,
+ strlen
+ (entry->
+ mnt_dir));
+ mnt_fsname =
+ realloc(mnt_fsname,
+ strlen
+ (entry->
+ mnt_fsname));
copy_string = 1;
}
@@ -65,17 +82,22 @@
if (copy_string != 0) {
strcpy(mnt_dir, entry->mnt_dir);
- strcpy(mnt_fsname, entry->mnt_fsname);
+ strcpy(mnt_fsname,
+ entry->mnt_fsname);
#if DEBUG
- printf("%s is a subset of %s\n", path, entry->mnt_dir);
+ printf("%s is a subset of %s\n",
+ path, entry->mnt_dir);
} else {
- printf("%s is not a subset of %s\n", path, entry->mnt_dir);
+ printf
+ ("%s is not a subset of %s\n",
+ path, entry->mnt_dir);
#endif
}
#if DEBUG
} else {
- printf("%s is not a subset of %s\n", path, entry->mnt_dir);
+ printf("%s is not a subset of %s\n",
+ path, entry->mnt_dir);
#endif
}
@@ -111,8 +133,7 @@
*
* Returns NULL if memory couldn't be allocated.
*/
-char *
-get_mountpoint(const char *path)
+char *get_mountpoint(const char *path)
{
char *mnt_dir = NULL;
@@ -124,8 +145,7 @@
if (path == NULL) {
errno = EINVAL;
} else if ((resolved_path = realpath(path, NULL)) != NULL &&
- (mtab_f = setmntent("/etc/mtab", "r")) != NULL)
- {
+ (mtab_f = setmntent("/etc/mtab", "r")) != NULL) {
do {
@@ -133,20 +153,31 @@
if (entry != NULL) {
- if (!strncmp(entry->mnt_dir, resolved_path, strlen(entry->mnt_dir))) {
+ if (!strncmp
+ (entry->mnt_dir, resolved_path,
+ strlen(entry->mnt_dir))) {
char copy_string = 0;
if (mnt_dir == NULL) {
- mnt_dir = malloc(strlen(entry->mnt_dir)+1);
+ mnt_dir =
+ malloc(strlen
+ (entry->mnt_dir) +
+ 1);
copy_string = mnt_dir != NULL;
} else {
- if (!strncmp(entry->mnt_dir, mnt_dir, strlen(entry->mnt_dir))) {
+ if (!strncmp
+ (entry->mnt_dir, mnt_dir,
+ strlen(entry->mnt_dir))) {
- mnt_dir = realloc(mnt_dir, strlen(entry->mnt_dir));
+ mnt_dir =
+ realloc(mnt_dir,
+ strlen
+ (entry->
+ mnt_dir));
copy_string = 1;
}
@@ -156,15 +187,19 @@
if (copy_string != 0) {
strcpy(mnt_dir, entry->mnt_dir);
#if DEBUG
- printf("%s is a subset of %s\n", path, entry->mnt_dir);
+ printf("%s is a subset of %s\n",
+ path, entry->mnt_dir);
} else {
- printf("%s is not a subset of %s\n", path, entry->mnt_dir);
+ printf
+ ("%s is not a subset of %s\n",
+ path, entry->mnt_dir);
#endif
}
#if DEBUG
} else {
- printf("%s is not a subset of %s\n", path, entry->mnt_dir);
+ printf("%s is not a subset of %s\n",
+ path, entry->mnt_dir);
#endif
}
@@ -183,16 +218,16 @@
return mnt_dir;
}
+
#if UNIT_TEST
-int
-main(void)
+int main(void)
{
char *mnt_fsname;
char *paths[] = {
"/home",
"/mnt",
- "/tmp/foo", /* mkdir /tmp/foo; mount -t tmpfs none /tmp/foo/ */
+ "/tmp/foo", /* mkdir /tmp/foo; mount -t tmpfs none /tmp/foo/ */
"/proc",
"/optimus/store"
};
diff --git a/lib/open_flags.c b/lib/open_flags.c
index ee3c13f..ff37a16 100644
--- a/lib/open_flags.c
+++ b/lib/open_flags.c
@@ -101,194 +101,192 @@
#include <unistd.h>
#include <fcntl.h>
#include <sys/param.h>
-#include <string.h> /* strcat */
+#include <string.h> /* strcat */
#include "open_flags.h"
#define UNKNOWN_SYMBOL "UNKNOWN"
-static char Open_symbols[512]; /* space for openflags2symbols return value */
+static char Open_symbols[512]; /* space for openflags2symbols return value */
struct open_flag_t {
- char *symbol;
- int flag;
+ char *symbol;
+ int flag;
};
static struct open_flag_t Open_flags[] = {
- { "O_RDONLY", O_RDONLY },
- { "O_WRONLY", O_WRONLY },
- { "O_RDWR", O_RDWR },
- { "O_SYNC", O_SYNC },
- { "O_CREAT", O_CREAT },
- { "O_TRUNC", O_TRUNC },
- { "O_EXCL", O_EXCL },
- { "O_APPEND", O_APPEND },
- { "O_NONBLOCK", O_NONBLOCK },
+ {"O_RDONLY", O_RDONLY},
+ {"O_WRONLY", O_WRONLY},
+ {"O_RDWR", O_RDWR},
+ {"O_SYNC", O_SYNC},
+ {"O_CREAT", O_CREAT},
+ {"O_TRUNC", O_TRUNC},
+ {"O_EXCL", O_EXCL},
+ {"O_APPEND", O_APPEND},
+ {"O_NONBLOCK", O_NONBLOCK},
#if O_NOCTTY
- { "O_NOCTTY", O_NOCTTY },
+ {"O_NOCTTY", O_NOCTTY},
#endif
#if O_DSYNC
- { "O_DSYNC", O_DSYNC },
+ {"O_DSYNC", O_DSYNC},
#endif
#if O_RSYNC
- { "O_RSYNC", O_RSYNC },
+ {"O_RSYNC", O_RSYNC},
#endif
#if O_ASYNC
- { "O_ASYNC", O_ASYNC },
+ {"O_ASYNC", O_ASYNC},
#endif
#if O_PTYIGN
- { "O_PTYIGN", O_PTYIGN },
+ {"O_PTYIGN", O_PTYIGN},
#endif
#if O_NDELAY
- { "O_NDELAY", O_NDELAY },
+ {"O_NDELAY", O_NDELAY},
#endif
#if O_RAW
- { "O_RAW", O_RAW },
+ {"O_RAW", O_RAW},
#endif
#ifdef O_SSD
- { "O_SSD", O_SSD },
+ {"O_SSD", O_SSD},
#endif
#if O_BIG
- { "O_BIG", O_BIG },
+ {"O_BIG", O_BIG},
#endif
#if O_PLACE
- { "O_PLACE", O_PLACE },
+ {"O_PLACE", O_PLACE},
#endif
#if O_RESTART
- { "O_RESTART", O_RESTART },
+ {"O_RESTART", O_RESTART},
#endif
#if O_SFSXOP
- { "O_SFSXOP", O_SFSXOP },
+ {"O_SFSXOP", O_SFSXOP},
#endif
#if O_SFS_DEFER_TM
- { "O_SFS_DEFER_TM", O_SFS_DEFER_TM },
+ {"O_SFS_DEFER_TM", O_SFS_DEFER_TM},
#endif
#if O_WELLFORMED
- { "O_WELLFORMED", O_WELLFORMED },
+ {"O_WELLFORMED", O_WELLFORMED},
#endif
#if O_LDRAW
- { "O_LDRAW", O_LDRAW },
+ {"O_LDRAW", O_LDRAW},
#endif
#if O_T3D
- { "O_T3D", O_T3D },
+ {"O_T3D", O_T3D},
#endif /* O_T3D */
#if O_PARALLEL
- { "O_PARALLEL", O_PARALLEL },
- { "O_FSA", O_PARALLEL|O_WELLFORMED|O_RAW }, /* short cut */
+ {"O_PARALLEL", O_PARALLEL},
+ {"O_FSA", O_PARALLEL | O_WELLFORMED | O_RAW}, /* short cut */
#endif /* O_PARALLEL */
#ifdef O_LARGEFILE
- { "O_LARGEFILE", O_LARGEFILE },
+ {"O_LARGEFILE", O_LARGEFILE},
#endif
#ifdef O_DIRECT
- { "O_DIRECT", O_DIRECT },
+ {"O_DIRECT", O_DIRECT},
#endif
#ifdef O_PRIV
- { "O_PRIV", O_PRIV },
+ {"O_PRIV", O_PRIV},
#endif
};
-int
-parse_open_flags(char *string, char **badname)
+int parse_open_flags(char *string, char **badname)
{
- int bits = 0;
- char *name;
- char *cc;
- char savecc;
- int found;
- unsigned int ind;
+ int bits = 0;
+ char *name;
+ char *cc;
+ char savecc;
+ int found;
+ unsigned int ind;
- name=string;
- cc=name;
+ name = string;
+ cc = name;
- while ( 1 ) {
+ while (1) {
- for (; ((*cc != ',') && (*cc != '\0')); cc++);
- savecc = *cc;
- *cc = '\0';
+ for (; ((*cc != ',') && (*cc != '\0')); cc++) ;
+ savecc = *cc;
+ *cc = '\0';
- found = 0;
+ found = 0;
- for (ind=0; ind < sizeof(Open_flags)/sizeof(struct open_flag_t); ind++) {
- if (strcmp(name, Open_flags[ind].symbol) == 0) {
- bits |= Open_flags[ind].flag;
- found=1;
- break;
- }
- }
+ for (ind = 0;
+ ind < sizeof(Open_flags) / sizeof(struct open_flag_t);
+ ind++) {
+ if (strcmp(name, Open_flags[ind].symbol) == 0) {
+ bits |= Open_flags[ind].flag;
+ found = 1;
+ break;
+ }
+ }
- *cc = savecc; /* restore string */
+ *cc = savecc; /* restore string */
- if (found == 0) { /* invalid name */
- if (badname != NULL)
- *badname = name;
- return -1;
- }
+ if (found == 0) { /* invalid name */
+ if (badname != NULL)
+ *badname = name;
+ return -1;
+ }
- if (savecc == '\0')
- break;
+ if (savecc == '\0')
+ break;
- name = ++cc;
+ name = ++cc;
- } /* end while */
+ } /* end while */
- return bits;
+ return bits;
-} /* end of parse_open_flags */
+} /* end of parse_open_flags */
-
-char *
-openflags2symbols(int openflags, char *sep, int mode)
+char *openflags2symbols(int openflags, char *sep, int mode)
{
- int ind;
- int size;
- int bits = openflags;
- int havesome=0;
+ int ind;
+ int size;
+ int bits = openflags;
+ int havesome = 0;
- Open_symbols[0]='\0';
+ Open_symbols[0] = '\0';
- size=sizeof(Open_flags)/sizeof(struct open_flag_t);
+ size = sizeof(Open_flags) / sizeof(struct open_flag_t);
- /*
- * Deal with special case of O_RDONLY. If O_WRONLY nor O_RDWR
- * bits are not set, assume O_RDONLY.
- */
+ /*
+ * Deal with special case of O_RDONLY. If O_WRONLY nor O_RDWR
+ * bits are not set, assume O_RDONLY.
+ */
- if ((bits & (O_WRONLY | O_RDWR)) == 0) {
- strcat(Open_symbols, "O_RDONLY");
- havesome=1;
- }
-
- /*
- * Loop through all but O_RDONLY elments of Open_flags
- */
- for (ind=1; ind < size; ind++) {
-
- if ((bits & Open_flags[ind].flag) == Open_flags[ind].flag) {
- if (havesome)
- strcat(Open_symbols, sep);
-
- strcat(Open_symbols, Open_flags[ind].symbol);
- havesome++;
-
- /* remove flag bits from bits */
- bits = bits & (~Open_flags[ind].flag);
+ if ((bits & (O_WRONLY | O_RDWR)) == 0) {
+ strcat(Open_symbols, "O_RDONLY");
+ havesome = 1;
}
- }
- /*
- * If not all bits were identified and mode was equal to 1,
- * added UNKNOWN_SYMBOL to return string
- */
- if (bits && mode == 1) { /* not all bits were identified */
- if (havesome)
- strcat(Open_symbols, sep);
- strcat(Open_symbols, UNKNOWN_SYMBOL);
- }
+ /*
+ * Loop through all but O_RDONLY elments of Open_flags
+ */
+ for (ind = 1; ind < size; ind++) {
- return Open_symbols;
+ if ((bits & Open_flags[ind].flag) == Open_flags[ind].flag) {
+ if (havesome)
+ strcat(Open_symbols, sep);
-} /* end of openflags2symbols */
+ strcat(Open_symbols, Open_flags[ind].symbol);
+ havesome++;
+ /* remove flag bits from bits */
+ bits = bits & (~Open_flags[ind].flag);
+ }
+ }
+
+ /*
+ * If not all bits were identified and mode was equal to 1,
+ * added UNKNOWN_SYMBOL to return string
+ */
+ if (bits && mode == 1) { /* not all bits were identified */
+ if (havesome)
+ strcat(Open_symbols, sep);
+ strcat(Open_symbols, UNKNOWN_SYMBOL);
+ }
+
+ return Open_symbols;
+
+} /* end of openflags2symbols */
#ifdef UNIT_TEST
@@ -297,34 +295,36 @@
* parse_open_flags and openflags2symbols functions.
*/
-int
-main(argc, argv)
+int main(argc, argv)
int argc;
char **argv;
{
- int bits;
- int ret;
- char *err;
+ int bits;
+ int ret;
+ char *err;
- if (argc == 1) {
- printf("Usage: %s openflagsbits\n\t%s symbols\n", argv[0], argv[0]);
- exit(1);
- }
+ if (argc == 1) {
+ printf("Usage: %s openflagsbits\n\t%s symbols\n", argv[0],
+ argv[0]);
+ exit(1);
+ }
- if (sscanf(argv[1], "%i", &bits) == 1) {
- printf("openflags2symbols(%#o, \",\", 1) returned %s\n",
- bits, openflags2symbols(bits, ",", 1));
+ if (sscanf(argv[1], "%i", &bits) == 1) {
+ printf("openflags2symbols(%#o, \",\", 1) returned %s\n",
+ bits, openflags2symbols(bits, ",", 1));
- } else {
- ret=parse_open_flags(argv[1], &err);
- if (ret == -1)
- printf("parse_open_flags(%s, &err) returned -1, err = %s\n",
- argv[0], err);
- else
- printf("parse_open_flags(%s, &err) returned %#o\n", argv[0], ret);
- }
+ } else {
+ ret = parse_open_flags(argv[1], &err);
+ if (ret == -1)
+ printf
+ ("parse_open_flags(%s, &err) returned -1, err = %s\n",
+ argv[0], err);
+ else
+ printf("parse_open_flags(%s, &err) returned %#o\n",
+ argv[0], ret);
+ }
- exit(0);
+ exit(0);
}
#endif /* end of UNIT_TEST */
diff --git a/lib/parse_opts.c b/lib/parse_opts.c
index 211299d..d07217c 100644
--- a/lib/parse_opts.c
+++ b/lib/parse_opts.c
@@ -84,7 +84,7 @@
#endif /* UNIT_TEST */
#include "test.h"
-#define _USC_LIB_ 1 /* indicates we are the library to the usctest.h include */
+#define _USC_LIB_ 1 /* indicates we are the library to the usctest.h include */
#include "usctest.h"
#ifndef USC_COPIES
@@ -100,80 +100,84 @@
#endif
/* The timing information block. */
-struct tblock tblock={0,((long) -1)>>1,0,0};
+struct tblock tblock = { 0, ((long)-1) >> 1, 0, 0 };
#ifdef GARRETT_IS_A_PEDANTIC_BASTARD
-extern pid_t spawned_program_pid;
+extern pid_t spawned_program_pid;
#endif
/* Define flags and args for standard options */
-int STD_FUNCTIONAL_TEST=1, /* flag indicating to do functional testing code */
- STD_TIMING_ON=0, /* flag indicating to print timing stats */
- STD_PAUSE=0, /* flag indicating to pause before actual start, */
- /* for contention mode */
- STD_INFINITE=0, /* flag indciating to loop forever */
- STD_LOOP_COUNT=1, /* number of iterations */
- STD_COPIES=1, /* number of copies */
- STD_ERRNO_LOG=0; /* flag indicating to do errno logging */
+int STD_FUNCTIONAL_TEST = 1, /* flag indicating to do functional testing code */
+ STD_TIMING_ON = 0, /* flag indicating to print timing stats */
+ STD_PAUSE = 0, /* flag indicating to pause before actual start, */
+ /* for contention mode */
+ STD_INFINITE = 0, /* flag indciating to loop forever */
+ STD_LOOP_COUNT = 1, /* number of iterations */
+ STD_COPIES = 1, /* number of copies */
+ STD_ERRNO_LOG = 0; /* flag indicating to do errno logging */
-float STD_LOOP_DURATION=0.0, /* duration value in fractional seconds */
- STD_LOOP_DELAY=0.0; /* loop delay value in fractional seconds */
-
+float STD_LOOP_DURATION = 0.0, /* duration value in fractional seconds */
+ STD_LOOP_DELAY = 0.0; /* loop delay value in fractional seconds */
char **STD_opt_arr = NULL; /* array of option strings */
-int STD_nopts=0, /* number of elements in STD_opt_arr */
- STD_argind=1; /* argv index to next argv element */
+int STD_nopts = 0, /* number of elements in STD_opt_arr */
+ STD_argind = 1; /* argv index to next argv element */
/* (first argument) */
/* To getopt users, it is like optind */
/*
* The following variables are to support system testing additions.
*/
-static int STD_TP_barrier=0; /* flag to do barrier in TEST_PAUSE */
+static int STD_TP_barrier = 0; /* flag to do barrier in TEST_PAUSE */
/* 2 - wait_barrier(), 3 - set_barrier(), * - barrier() */
-static int STD_LP_barrier=0; /* flag to do barrier in TEST_LOOPING */
+static int STD_LP_barrier = 0; /* flag to do barrier in TEST_LOOPING */
/* 2 - wait_barrier(), 3 - set_barrier(), * - barrier() */
-static int STD_TP_shmem_sz=0; /* shmalloc this many words per pe in TEST_PAUSE */
-static int STD_LD_shmem=0; /* flag to do shmem_puts and shmem_gets during delay */
-static int STD_LP_shmem=0; /* flag to do shmem_puts and gets during TEST_LOOPING */
-static int STD_LD_recfun=0; /* do recressive function calls in loop delay */
-static int STD_LP_recfun=0; /* do recressive function calls in TEST_LOOPING */
-static int STD_TP_sbrk=0; /* do sbrk in TEST_PAUSE */
-static int STD_LP_sbrk=0; /* do sbrk in TEST_LOOPING */
-static char *STD_start_break=0; /* original sbrk size */
-static int Debug=0;
+static int STD_TP_shmem_sz = 0; /* shmalloc this many words per pe in TEST_PAUSE */
+static int STD_LD_shmem = 0; /* flag to do shmem_puts and shmem_gets during delay */
+static int STD_LP_shmem = 0; /* flag to do shmem_puts and gets during TEST_LOOPING */
+static int STD_LD_recfun = 0; /* do recressive function calls in loop delay */
+static int STD_LP_recfun = 0; /* do recressive function calls in TEST_LOOPING */
+static int STD_TP_sbrk = 0; /* do sbrk in TEST_PAUSE */
+static int STD_LP_sbrk = 0; /* do sbrk in TEST_LOOPING */
+static char *STD_start_break = 0; /* original sbrk size */
+static int Debug = 0;
struct std_option_t {
- char *optstr;
- char *help;
- char *flag;
- char **arg;
+ char *optstr;
+ char *help;
+ char *flag;
+ char **arg;
} std_options[] = {
- { "c:", " -c n Run n copies concurrently\n", NULL, NULL},
- { "e" , " -e Turn on errno logging\n", NULL, NULL},
- { "f" , " -f Turn off functional testing\n", NULL, NULL},
- { "h" , " -h Show this help screen\n", NULL, NULL},
- { "i:", " -i n Execute test n times\n", NULL, NULL},
- { "I:", " -I x Execute test for x seconds\n", NULL, NULL},
- { "p" , " -p Pause for SIGUSR1 before starting\n", NULL, NULL},
- { "P:", " -P x Pause for x seconds between iterations\n", NULL, NULL},
- { "t" , " -t Turn on syscall timing\n", NULL, NULL},
+ {
+ "c:", " -c n Run n copies concurrently\n", NULL, NULL}, {
+ "e", " -e Turn on errno logging\n", NULL, NULL}, {
+ "f", " -f Turn off functional testing\n", NULL, NULL}, {
+ "h", " -h Show this help screen\n", NULL, NULL}, {
+ "i:", " -i n Execute test n times\n", NULL, NULL}, {
+ "I:", " -I x Execute test for x seconds\n", NULL, NULL}, {
+ "p", " -p Pause for SIGUSR1 before starting\n", NULL, NULL}, {
+ "P:", " -P x Pause for x seconds between iterations\n", NULL, NULL},
+ {
+ "t", " -t Turn on syscall timing\n", NULL, NULL},
#ifdef UCLINUX
- { "C:", " -C ARG Run the child process with arguments ARG (for internal use)\n",
- NULL, NULL},
+ {
+ "C:",
+ " -C ARG Run the child process with arguments ARG (for internal use)\n",
+ NULL, NULL},
#endif
- {NULL, NULL, NULL, NULL}};
+ {
+NULL, NULL, NULL, NULL}};
-void print_help(void (*user_help)());
+void print_help(void (*user_help) ());
/*
* Structure for usc_recressive_func argument
*/
struct usc_bigstack_t {
- char space[4096];
+ char space[4096];
};
-static struct usc_bigstack_t *STD_bigstack=NULL;
+static struct usc_bigstack_t *STD_bigstack = NULL;
/*
* Counter of errnos returned (-e option). Indexed by errno.
@@ -205,386 +209,411 @@
/**********************************************************************
* parse_opts:
**********************************************************************/
-char *
-parse_opts(int ac, char **av, const option_t *user_optarr, void (*uhf)())
+char *parse_opts(int ac, char **av, const option_t * user_optarr,
+ void (*uhf) ())
{
- int found; /* flag to indicate that an option specified was */
- /* found in the user's list */
- int k; /* scratch integer for returns and short time usage */
- float ftmp; /* tmp float for parsing env variables */
- char *ptr; /* used in getting env variables */
- int options=0; /* no options specified */
- int optstrlen, i;
- char *optionstr;
- int opt; /* return of getopt */
+ int found; /* flag to indicate that an option specified was */
+ /* found in the user's list */
+ int k; /* scratch integer for returns and short time usage */
+ float ftmp; /* tmp float for parsing env variables */
+ char *ptr; /* used in getting env variables */
+ int options = 0; /* no options specified */
+ int optstrlen, i;
+ char *optionstr;
+ int opt; /* return of getopt */
- /*
- * If not the first time this function is called, release the old STD_opt_arr
- * vector.
- */
+ /*
+ * If not the first time this function is called, release the old STD_opt_arr
+ * vector.
+ */
#ifdef GARRETT_IS_A_PEDANTIC_BASTARD
- spawned_program_pid = getpid();
+ spawned_program_pid = getpid();
#endif
- if (STD_opt_arr != NULL) {
- free(STD_opt_arr);
- STD_opt_arr = NULL;
- }
- /* Calculate how much space we need for the option string */
- optstrlen = 0;
- for (i = 0; std_options[i].optstr; ++i)
- optstrlen += strlen(std_options[i].optstr);
- if (user_optarr)
- for (i = 0; user_optarr[i].option; ++i) {
- if (strlen(user_optarr[i].option) > 2)
- return "parse_opts: ERROR - Only short options are allowed";
- optstrlen += strlen(user_optarr[i].option);
+ if (STD_opt_arr != NULL) {
+ free(STD_opt_arr);
+ STD_opt_arr = NULL;
}
- optstrlen += 1;
+ /* Calculate how much space we need for the option string */
+ optstrlen = 0;
+ for (i = 0; std_options[i].optstr; ++i)
+ optstrlen += strlen(std_options[i].optstr);
+ if (user_optarr)
+ for (i = 0; user_optarr[i].option; ++i) {
+ if (strlen(user_optarr[i].option) > 2)
+ return
+ "parse_opts: ERROR - Only short options are allowed";
+ optstrlen += strlen(user_optarr[i].option);
+ }
+ optstrlen += 1;
- /* Create the option string for getopt */
- optionstr = malloc(optstrlen);
- if (!optionstr)
- return "parse_opts: ERROR - Could not allocate memory for optionstr";
+ /* Create the option string for getopt */
+ optionstr = malloc(optstrlen);
+ if (!optionstr)
+ return
+ "parse_opts: ERROR - Could not allocate memory for optionstr";
- optionstr[0] = '\0';
+ optionstr[0] = '\0';
- for (i = 0; std_options[i].optstr; ++i)
- strcat(optionstr, std_options[i].optstr);
- if (user_optarr)
- for (i = 0; user_optarr[i].option; ++i)
- /* only add the option if it wasn't there already */
- if (strchr(optionstr, user_optarr[i].option[0]) == NULL)
- strcat(optionstr, user_optarr[i].option);
+ for (i = 0; std_options[i].optstr; ++i)
+ strcat(optionstr, std_options[i].optstr);
+ if (user_optarr)
+ for (i = 0; user_optarr[i].option; ++i)
+ /* only add the option if it wasn't there already */
+ if (strchr(optionstr, user_optarr[i].option[0]) == NULL)
+ strcat(optionstr, user_optarr[i].option);
#if DEBUG > 1
- printf("STD_nopts = %d\n", STD_nopts);
+ printf("STD_nopts = %d\n", STD_nopts);
#endif
- /*
- * Loop through av parsing options.
- */
- while ((opt = getopt(ac, av, optionstr)) > 0) {
+ /*
+ * Loop through av parsing options.
+ */
+ while ((opt = getopt(ac, av, optionstr)) > 0) {
- STD_argind = optind;
+ STD_argind = optind;
#if DEBUG > 0
- printf("parse_opts: getopt returned '%c'\n", opt);
+ printf("parse_opts: getopt returned '%c'\n", opt);
#endif
- switch (opt) {
- case '?': /* Unknown option */
+ switch (opt) {
+ case '?': /* Unknown option */
return "Unknown option";
break;
- case ':': /* Missing Arg */
+ case ':': /* Missing Arg */
return "Missing argument";
break;
- case 'i': /* Iterations */
+ case 'i': /* Iterations */
options |= OPT_iteration;
STD_LOOP_COUNT = atoi(optarg);
- if (STD_LOOP_COUNT == 0) STD_INFINITE = 1;
+ if (STD_LOOP_COUNT == 0)
+ STD_INFINITE = 1;
break;
- case 'P': /* Delay between iterations */
+ case 'P': /* Delay between iterations */
options |= OPT_delay;
STD_LOOP_DELAY = atof(optarg);
break;
- case 'I': /* Time duration */
+ case 'I': /* Time duration */
options |= OPT_duration;
STD_LOOP_DURATION = atof(optarg);
- if (STD_LOOP_DURATION == 0.0) STD_INFINITE=1;
+ if (STD_LOOP_DURATION == 0.0)
+ STD_INFINITE = 1;
break;
- case 'c': /* Copies */
+ case 'c': /* Copies */
fprintf(stderr,
- "WARNING * WARNING * WARNING * WARNING * "
- "WARNING * WARNING * WARNING * WARNING\n\n"
- "The -c option is broken by desing. See:\n\n"
- "http://www.mail-archive.com/"
- "ltp-list@lists.sourceforge.net/msg13418.html\n"
- "\nIn short don't use it in runtest files "
- "as the option will be removed.\n\n"
+ "WARNING * WARNING * WARNING * WARNING * "
+ "WARNING * WARNING * WARNING * WARNING\n\n"
+ "The -c option is broken by desing. See:\n\n"
+ "http://www.mail-archive.com/"
+ "ltp-list@lists.sourceforge.net/msg13418.html\n"
+ "\nIn short don't use it in runtest files "
+ "as the option will be removed.\n\n"
"WARNING * WARNING * WARNING * WARNING * "
"WARNING * WARNING * WARNING * WARNING\n\n");
options |= OPT_copies;
STD_COPIES = atoi(optarg);
break;
- case 'f': /* Functional testing */
+ case 'f': /* Functional testing */
STD_FUNCTIONAL_TEST = 0;
break;
- case 'p': /* Pause for SIGUSR1 */
+ case 'p': /* Pause for SIGUSR1 */
STD_PAUSE = 1;
break;
- case 't': /* syscall timing */
+ case 't': /* syscall timing */
STD_TIMING_ON = 1;
break;
- case 'e': /* errno loggin */
+ case 'e': /* errno loggin */
STD_ERRNO_LOG = 1;
break;
- case 'h': /* Help */
+ case 'h': /* Help */
print_help(uhf);
exit(0);
break;
#ifdef UCLINUX
- case 'C': /* Run child */
+ case 'C': /* Run child */
child_args = optarg;
break;
#endif
default:
- /* Check all the user specified options */
- found=0;
- for (i = 0; user_optarr[i].option; ++i) {
+ /* Check all the user specified options */
+ found = 0;
+ for (i = 0; user_optarr[i].option; ++i) {
- if (opt == user_optarr[i].option[0]) {
- /* Yup, This is a user option, set the flag and look for argument */
- if (user_optarr[i].flag) {
- *user_optarr[i].flag=1;
- }
- found++;
+ if (opt == user_optarr[i].option[0]) {
+ /* Yup, This is a user option, set the flag and look for argument */
+ if (user_optarr[i].flag) {
+ *user_optarr[i].flag = 1;
+ }
+ found++;
- /* save the argument at the user's location */
- if (user_optarr[i].option[strlen(user_optarr[i].option)-1] == ':') {
- *user_optarr[i].arg = optarg;
- }
- break; /* option found - break out of the for loop */
- }
- }
- /* This condition "should never happen". SO CHECK FOR IT!!!! */
- if (!found) {
- sprintf(Mesg2,
- "parse_opts: ERROR - option:\"%c\" NOT FOUND... INTERNAL "
- "ERROR", opt);
- return(Mesg2);
- }
+ /* save the argument at the user's location */
+ if (user_optarr[i].
+ option[strlen(user_optarr[i].option)
+ - 1] == ':') {
+ *user_optarr[i].arg = optarg;
+ }
+ break; /* option found - break out of the for loop */
+ }
+ }
+ /* This condition "should never happen". SO CHECK FOR IT!!!! */
+ if (!found) {
+ sprintf(Mesg2,
+ "parse_opts: ERROR - option:\"%c\" NOT FOUND... INTERNAL "
+ "ERROR", opt);
+ return (Mesg2);
+ }
+ }
+
+ } /* end of while */
+ free(optionstr);
+
+ STD_argind = optind;
+
+ /*
+ * Turn on debug
+ */
+ if ((ptr = getenv("USC_DEBUG")) != NULL) {
+ Debug = 1;
+ printf("env USC_DEBUG is defined, turning on debug\n");
+ }
+ if ((ptr = getenv("USC_VERBOSE")) != NULL) {
+ Debug = 1;
+ printf("env USC_VERBOSE is defined, turning on debug\n");
}
- } /* end of while */
- free(optionstr);
+ /*
+ * If the USC_ITERATION_ENV environmental variable is set to
+ * a number, use that number as iteration count (same as -c option).
+ * The -c option with arg will be used even if this env var is set.
+ */
+ if (!(options & OPT_iteration)
+ && (ptr = getenv(USC_ITERATION_ENV)) != NULL) {
+ if (sscanf(ptr, "%i", &k) == 1) {
+ if (k == 0) { /* if arg is 0, set infinite loop flag */
+ STD_INFINITE = 1;
+ if (Debug)
+ printf
+ ("Using env %s, set STD_INFINITE to 1\n",
+ USC_ITERATION_ENV);
+ } else { /* else, set the loop count to the arguement */
+ STD_LOOP_COUNT = k;
+ if (Debug)
+ printf
+ ("Using env %s, set STD_LOOP_COUNT to %d\n",
+ USC_ITERATION_ENV, k);
+ }
+ }
+ }
- STD_argind = optind;
-
- /*
- * Turn on debug
- */
- if ((ptr = getenv("USC_DEBUG")) != NULL) {
- Debug = 1;
- printf("env USC_DEBUG is defined, turning on debug\n");
- }
- if ((ptr = getenv("USC_VERBOSE")) != NULL) {
- Debug = 1;
- printf("env USC_VERBOSE is defined, turning on debug\n");
- }
-
- /*
- * If the USC_ITERATION_ENV environmental variable is set to
- * a number, use that number as iteration count (same as -c option).
- * The -c option with arg will be used even if this env var is set.
- */
- if (!(options & OPT_iteration) && (ptr = getenv(USC_ITERATION_ENV)) != NULL) {
- if (sscanf(ptr, "%i", &k) == 1) {
- if (k == 0) { /* if arg is 0, set infinite loop flag */
- STD_INFINITE = 1;
+ /*
+ * If the USC_NO_FUNC_CHECK environmental variable is set, we'll
+ * unset the STD_FUNCTIONAL_TEST variable.
+ */
+ if (!(options & OPT_nofunccheck) &&
+ (ptr = getenv(USC_NO_FUNC_CHECK)) != NULL) {
+ STD_FUNCTIONAL_TEST = 0; /* Turn off functional testing */
if (Debug)
- printf("Using env %s, set STD_INFINITE to 1\n",
- USC_ITERATION_ENV);
- } else { /* else, set the loop count to the arguement */
- STD_LOOP_COUNT=k;
+ printf("Using env %s, set STD_FUNCTIONAL_TEST to 0\n",
+ USC_NO_FUNC_CHECK);
+ }
+
+ /*
+ * If the USC_LOOP_WALLTIME environmental variable is set,
+ * use that number as duration (same as -I option).
+ * The -I option with arg will be used even if this env var is set.
+ */
+
+ if (!(options & OPT_duration) &&
+ (ptr = getenv(USC_LOOP_WALLTIME)) != NULL) {
+ if (sscanf(ptr, "%f", &ftmp) == 1 && ftmp >= 0.0) {
+ STD_LOOP_DURATION = ftmp;
+ if (Debug)
+ printf
+ ("Using env %s, set STD_LOOP_DURATION to %f\n",
+ USC_LOOP_WALLTIME, ftmp);
+ if (STD_LOOP_DURATION == 0.0) { /* if arg is 0, set infinite loop flag */
+ STD_INFINITE = 1;
+ if (Debug)
+ printf
+ ("Using env %s, set STD_INFINITE to 1\n",
+ USC_LOOP_WALLTIME);
+ }
+ }
+ }
+ if (!(options & OPT_duration) && (ptr = getenv("USC_DURATION")) != NULL) {
+ if (sscanf(ptr, "%f", &ftmp) == 1 && ftmp >= 0.0) {
+ STD_LOOP_DURATION = ftmp;
+ if (Debug)
+ printf
+ ("Using env USC_DURATION, set STD_LOOP_DURATION to %f\n",
+ ftmp);
+ if (STD_LOOP_DURATION == 0.0) { /* if arg is 0, set infinite loop flag */
+ STD_INFINITE = 1;
+ if (Debug)
+ printf
+ ("Using env USC_DURATION, set STD_INFINITE to 1\n");
+ }
+ }
+ }
+ /*
+ * If the USC_LOOP_DELAY environmental variable is set,
+ * use that number as delay in factional seconds (same as -P option).
+ * The -P option with arg will be used even if this env var is set.
+ */
+ if (!(options & OPT_delay) && (ptr = getenv(USC_LOOP_DELAY)) != NULL) {
+ if (sscanf(ptr, "%f", &ftmp) == 1 && ftmp >= 0.0) {
+ STD_LOOP_DELAY = ftmp;
+ if (Debug)
+ printf
+ ("Using env %s, set STD_LOOP_DELAY = %f\n",
+ USC_LOOP_DELAY, ftmp);
+ }
+ }
+
+ /*
+ * If the USC_COPIES environmental variable is set,
+ * use that number as copies (same as -c option).
+ * The -c option with arg will be used even if this env var is set.
+ */
+ if (!(options & OPT_copies) && (ptr = getenv(USC_COPIES)) != NULL) {
+ if (sscanf(ptr, "%d", &STD_COPIES) == 1 && STD_COPIES >= 0) {
+ if (Debug)
+ printf("Using env %s, set STD_COPIES = %d\n",
+ USC_COPIES, STD_COPIES);
+ }
+ }
+
+ /*
+ * The following are special system testing envs to turn on special
+ * hooks in the code.
+ */
+ if ((ptr = getenv("USC_TP_BARRIER")) != NULL) {
+ if (sscanf(ptr, "%i", &k) == 1 && k >= 0)
+ STD_TP_barrier = k;
+ else
+ STD_TP_barrier = 1;
if (Debug)
- printf("Using env %s, set STD_LOOP_COUNT to %d\n",
- USC_ITERATION_ENV, k);
- }
- }
- }
+ printf
+ ("using env USC_TP_BARRIER, Set STD_TP_barrier to %d\n",
+ STD_TP_barrier);
+ }
- /*
- * If the USC_NO_FUNC_CHECK environmental variable is set, we'll
- * unset the STD_FUNCTIONAL_TEST variable.
- */
- if (!(options & OPT_nofunccheck) &&
- (ptr = getenv(USC_NO_FUNC_CHECK)) != NULL) {
- STD_FUNCTIONAL_TEST=0; /* Turn off functional testing */
- if (Debug)
- printf("Using env %s, set STD_FUNCTIONAL_TEST to 0\n",
- USC_NO_FUNC_CHECK);
- }
+ if ((ptr = getenv("USC_LP_BARRIER")) != NULL) {
+ if (sscanf(ptr, "%i", &k) == 1 && k >= 0)
+ STD_LP_barrier = k;
+ else
+ STD_LP_barrier = 1;
+ if (Debug)
+ printf
+ ("using env USC_LP_BARRIER, Set STD_LP_barrier to %d\n",
+ STD_LP_barrier);
+ }
- /*
- * If the USC_LOOP_WALLTIME environmental variable is set,
- * use that number as duration (same as -I option).
- * The -I option with arg will be used even if this env var is set.
- */
+ if ((ptr = getenv("USC_TP_SHMEM")) != NULL) {
+ if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
+ STD_TP_shmem_sz = k;
+ if (Debug)
+ printf
+ ("Using env USC_TP_SHMEM, Set STD_TP_shmem_sz to %d\n",
+ STD_TP_shmem_sz);
+ }
+ }
- if (!(options & OPT_duration) &&
- (ptr = getenv(USC_LOOP_WALLTIME)) != NULL) {
- if (sscanf(ptr, "%f", &ftmp) == 1 && ftmp >= 0.0) {
- STD_LOOP_DURATION = ftmp;
- if (Debug)
- printf("Using env %s, set STD_LOOP_DURATION to %f\n",
- USC_LOOP_WALLTIME, ftmp);
- if (STD_LOOP_DURATION == 0.0) { /* if arg is 0, set infinite loop flag */
- STD_INFINITE = 1;
- if (Debug)
- printf("Using env %s, set STD_INFINITE to 1\n", USC_LOOP_WALLTIME);
- }
- }
- }
- if (!(options & OPT_duration) && (ptr = getenv("USC_DURATION")) != NULL) {
- if (sscanf(ptr, "%f", &ftmp) == 1 && ftmp >= 0.0) {
- STD_LOOP_DURATION = ftmp;
- if (Debug)
- printf("Using env USC_DURATION, set STD_LOOP_DURATION to %f\n", ftmp);
- if (STD_LOOP_DURATION == 0.0) { /* if arg is 0, set infinite loop flag */
- STD_INFINITE = 1;
- if (Debug)
- printf("Using env USC_DURATION, set STD_INFINITE to 1\n");
- }
- }
- }
- /*
- * If the USC_LOOP_DELAY environmental variable is set,
- * use that number as delay in factional seconds (same as -P option).
- * The -P option with arg will be used even if this env var is set.
- */
- if (!(options & OPT_delay) && (ptr = getenv(USC_LOOP_DELAY)) != NULL) {
- if (sscanf(ptr, "%f", &ftmp) == 1 && ftmp >= 0.0) {
- STD_LOOP_DELAY = ftmp;
- if (Debug)
- printf("Using env %s, set STD_LOOP_DELAY = %f\n",
- USC_LOOP_DELAY, ftmp);
- }
- }
+ if ((ptr = getenv("USC_LP_SHMEM")) != NULL) {
+ if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
+ STD_LP_shmem = k;
+ if (Debug)
+ printf
+ ("Using env USC_LP_SHMEM, Set STD_LP_shmem to %d\n",
+ STD_LP_shmem);
+ }
+ }
- /*
- * If the USC_COPIES environmental variable is set,
- * use that number as copies (same as -c option).
- * The -c option with arg will be used even if this env var is set.
- */
- if (!(options & OPT_copies) && (ptr = getenv(USC_COPIES)) != NULL) {
- if (sscanf(ptr, "%d", &STD_COPIES) == 1 && STD_COPIES >= 0) {
- if (Debug)
- printf("Using env %s, set STD_COPIES = %d\n",
- USC_COPIES, STD_COPIES);
- }
- }
+ if ((ptr = getenv("USC_LD_SHMEM")) != NULL) {
+ if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
+ STD_LD_shmem = k;
+ if (Debug)
+ printf
+ ("Using env USC_LD_SHMEM, Set STD_LD_shmem to %d\n",
+ STD_LD_shmem);
+ }
+ }
- /*
- * The following are special system testing envs to turn on special
- * hooks in the code.
- */
- if ((ptr = getenv("USC_TP_BARRIER")) != NULL) {
- if (sscanf(ptr, "%i", &k) == 1 && k >= 0)
- STD_TP_barrier=k;
- else
- STD_TP_barrier=1;
- if (Debug)
- printf("using env USC_TP_BARRIER, Set STD_TP_barrier to %d\n",
- STD_TP_barrier);
- }
-
- if ((ptr = getenv("USC_LP_BARRIER")) != NULL) {
- if (sscanf(ptr, "%i", &k) == 1 && k >= 0)
- STD_LP_barrier=k;
- else
- STD_LP_barrier=1;
- if (Debug)
- printf("using env USC_LP_BARRIER, Set STD_LP_barrier to %d\n",
- STD_LP_barrier);
- }
-
- if ((ptr = getenv("USC_TP_SHMEM")) != NULL) {
- if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
- STD_TP_shmem_sz=k;
- if (Debug)
- printf("Using env USC_TP_SHMEM, Set STD_TP_shmem_sz to %d\n",
- STD_TP_shmem_sz);
- }
- }
-
- if ((ptr = getenv("USC_LP_SHMEM")) != NULL) {
- if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
- STD_LP_shmem=k;
- if (Debug)
- printf("Using env USC_LP_SHMEM, Set STD_LP_shmem to %d\n",
- STD_LP_shmem);
- }
- }
-
- if ((ptr = getenv("USC_LD_SHMEM")) != NULL) {
- if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
- STD_LD_shmem=k;
- if (Debug)
- printf("Using env USC_LD_SHMEM, Set STD_LD_shmem to %d\n",
- STD_LD_shmem);
- }
- }
-
- if ((ptr = getenv("USC_TP_SBRK")) != NULL) {
- if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
- STD_TP_sbrk=k;
- if (Debug)
- printf("Using env USC_TP_SBRK, Set STD_TP_sbrk to %d\n",
- STD_TP_sbrk);
- }
- }
-
+ if ((ptr = getenv("USC_TP_SBRK")) != NULL) {
+ if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
+ STD_TP_sbrk = k;
+ if (Debug)
+ printf
+ ("Using env USC_TP_SBRK, Set STD_TP_sbrk to %d\n",
+ STD_TP_sbrk);
+ }
+ }
#if !defined(UCLINUX)
- if ((ptr = getenv("USC_LP_SBRK")) != NULL) {
- if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
- STD_LP_sbrk=k;
- if (Debug)
- printf("Using env USC_LP_SBRK, Set STD_LP_sbrk to %d\n",
- STD_LP_sbrk);
- }
- }
+ if ((ptr = getenv("USC_LP_SBRK")) != NULL) {
+ if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
+ STD_LP_sbrk = k;
+ if (Debug)
+ printf
+ ("Using env USC_LP_SBRK, Set STD_LP_sbrk to %d\n",
+ STD_LP_sbrk);
+ }
+ }
#endif /* if !defined(UCLINUX) */
- if ((ptr = getenv("USC_LP_RECFUN")) != NULL) {
- if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
- STD_LP_recfun = k;
- if (STD_bigstack != NULL)
- STD_bigstack = malloc(sizeof(struct usc_bigstack_t));
- if (Debug)
- printf("Using env USC_LP_RECFUN, Set STD_LP_recfun to %d\n",
- STD_LP_recfun);
- }
- }
+ if ((ptr = getenv("USC_LP_RECFUN")) != NULL) {
+ if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
+ STD_LP_recfun = k;
+ if (STD_bigstack != NULL)
+ STD_bigstack =
+ malloc(sizeof(struct usc_bigstack_t));
+ if (Debug)
+ printf
+ ("Using env USC_LP_RECFUN, Set STD_LP_recfun to %d\n",
+ STD_LP_recfun);
+ }
+ }
- if ((ptr = getenv("USC_LD_RECFUN")) != NULL) {
- if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
- STD_LD_recfun = k;
- if (STD_bigstack != NULL)
- STD_bigstack = malloc(sizeof(struct usc_bigstack_t));
- if (Debug)
- printf("Using env USC_LD_RECFUN, Set STD_LD_recfun to %d\n",
- STD_LD_recfun);
- }
- }
-
+ if ((ptr = getenv("USC_LD_RECFUN")) != NULL) {
+ if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
+ STD_LD_recfun = k;
+ if (STD_bigstack != NULL)
+ STD_bigstack =
+ malloc(sizeof(struct usc_bigstack_t));
+ if (Debug)
+ printf
+ ("Using env USC_LD_RECFUN, Set STD_LD_recfun to %d\n",
+ STD_LD_recfun);
+ }
+ }
#if UNIT_TEST
- printf("The following variables after option and env parsing:\n");
- printf("STD_FUNCTIONAL_TEST = %d\n", STD_FUNCTIONAL_TEST);
- printf("STD_LOOP_DURATION = %f\n", STD_LOOP_DURATION);
- printf("STD_LOOP_DELAY = %f\n", STD_LOOP_DELAY);
- printf("STD_COPIES = %d\n", STD_COPIES);
- printf("STD_LOOP_COUNT = %d\n", STD_LOOP_COUNT);
- printf("STD_INFINITE = %d\n", STD_INFINITE);
- printf("STD_TIMING_ON = %d\n", STD_TIMING_ON);
- printf("STD_ERRNO_LOG = %d\n", STD_ERRNO_LOG);
- printf("STD_PAUSE = %d\n", STD_PAUSE);
+ printf("The following variables after option and env parsing:\n");
+ printf("STD_FUNCTIONAL_TEST = %d\n", STD_FUNCTIONAL_TEST);
+ printf("STD_LOOP_DURATION = %f\n", STD_LOOP_DURATION);
+ printf("STD_LOOP_DELAY = %f\n", STD_LOOP_DELAY);
+ printf("STD_COPIES = %d\n", STD_COPIES);
+ printf("STD_LOOP_COUNT = %d\n", STD_LOOP_COUNT);
+ printf("STD_INFINITE = %d\n", STD_INFINITE);
+ printf("STD_TIMING_ON = %d\n", STD_TIMING_ON);
+ printf("STD_ERRNO_LOG = %d\n", STD_ERRNO_LOG);
+ printf("STD_PAUSE = %d\n", STD_PAUSE);
#endif
- return((char *) NULL);
+ return ((char *)NULL);
-} /* end of parse_opts */
+} /* end of parse_opts */
/*********************************************************************
* print_help() - print help message and user help message
*********************************************************************/
-void print_help(void (*user_help)())
+void print_help(void (*user_help) ())
{
- STD_opts_help();
+ STD_opts_help();
- if (user_help)
- user_help();
+ if (user_help)
+ user_help();
}
/*********************************************************************
@@ -592,12 +621,12 @@
*********************************************************************/
void STD_opts_help()
{
- int i;
+ int i;
- for (i = 0; std_options[i].optstr; ++i) {
- if (std_options[i].help)
- printf("%s", std_options[i].help);
- }
+ for (i = 0; std_options[i].optstr; ++i) {
+ if (std_options[i].help)
+ printf("%s", std_options[i].help);
+ }
}
/*
@@ -605,7 +634,7 @@
*/
void STD_go(int sig)
{
- return;
+ return;
}
/***********************************************************************
@@ -618,66 +647,64 @@
int usc_global_setup_hook()
{
#ifndef UCLINUX
- int cnt;
- /* temp variable to store old signal action to be restored after pause */
- int (*_TMP_FUNC)(void);
+ int cnt;
+ /* temp variable to store old signal action to be restored after pause */
+ int (*_TMP_FUNC) (void);
- /*
- * Fork STD_COPIES-1 copies.
- */
- for (cnt=1;cnt<STD_COPIES;cnt++) {
- switch (fork() ) {
- case -1:
- fprintf(stderr, "%s: fork failed: %d - %s\n",
- __FILE__, errno, strerror(errno));
- break;
- case 0: /* child */
- cnt=STD_COPIES; /* to stop the forking */
- break;
+ /*
+ * Fork STD_COPIES-1 copies.
+ */
+ for (cnt = 1; cnt < STD_COPIES; cnt++) {
+ switch (fork()) {
+ case -1:
+ fprintf(stderr, "%s: fork failed: %d - %s\n",
+ __FILE__, errno, strerror(errno));
+ break;
+ case 0: /* child */
+ cnt = STD_COPIES; /* to stop the forking */
+ break;
- default: /* parent */
- break;
+ default: /* parent */
+ break;
+ }
}
- }
- /*
- * pause waiting for sigusr1.
- */
- if (STD_PAUSE) {
- _TMP_FUNC = (int (*)())signal(SIGUSR1, STD_go);
- pause();
- signal(SIGUSR1, (void (*)())_TMP_FUNC);
- }
-
+ /*
+ * pause waiting for sigusr1.
+ */
+ if (STD_PAUSE) {
+ _TMP_FUNC = (int (*)())signal(SIGUSR1, STD_go);
+ pause();
+ signal(SIGUSR1, (void (*)())_TMP_FUNC);
+ }
#if !defined(UCLINUX)
- if (STD_TP_sbrk || STD_LP_sbrk) {
- STD_start_break=sbrk(0); /* get original sbreak size */
- }
+ if (STD_TP_sbrk || STD_LP_sbrk) {
+ STD_start_break = sbrk(0); /* get original sbreak size */
+ }
- if (STD_TP_sbrk) {
- sbrk(STD_TP_sbrk);
- if (Debug)
- printf("after sbrk(%d)\n", STD_TP_sbrk);
- }
-
+ if (STD_TP_sbrk) {
+ sbrk(STD_TP_sbrk);
+ if (Debug)
+ printf("after sbrk(%d)\n", STD_TP_sbrk);
+ }
#endif /* if !defined(UCLINUX) */
#endif
- return 0;
+ return 0;
}
-#define USECS_PER_SEC 1000000 /* microseconds per second */
+#define USECS_PER_SEC 1000000 /* microseconds per second */
/***********************************************************************
* Returns current time in microseconds since 1970.
***********************************************************************/
static uint64_t get_current_time(void)
{
- struct timeval curtime;
+ struct timeval curtime;
- gettimeofday(&curtime, NULL);
+ gettimeofday(&curtime, NULL);
- return (((uint64_t)curtime.tv_sec)*USECS_PER_SEC) + curtime.tv_usec;
+ return (((uint64_t) curtime.tv_sec) * USECS_PER_SEC) + curtime.tv_usec;
}
/***********************************************************************
@@ -695,107 +722,108 @@
***********************************************************************/
int usc_test_looping(int counter)
{
- static int first_time = 1;
- static uint64_t stop_time = 0;
- static uint64_t delay;
- uint64_t ct, end;
- int keepgoing = 0;
-
- /*
- * If this is the first iteration and we are looping for
- * duration of STD_LOOP_DURATION seconds (fractional) or
- * doing loop delays, get the clocks per second.
- */
- if (first_time) {
- first_time = 0;
+ static int first_time = 1;
+ static uint64_t stop_time = 0;
+ static uint64_t delay;
+ uint64_t ct, end;
+ int keepgoing = 0;
/*
- * If looping for duration, calculate stop time in
- * clocks.
+ * If this is the first iteration and we are looping for
+ * duration of STD_LOOP_DURATION seconds (fractional) or
+ * doing loop delays, get the clocks per second.
*/
- if (STD_LOOP_DURATION) {
- stop_time = (uint64_t)(USECS_PER_SEC * STD_LOOP_DURATION)
- + get_current_time();
+ if (first_time) {
+ first_time = 0;
+
+ /*
+ * If looping for duration, calculate stop time in
+ * clocks.
+ */
+ if (STD_LOOP_DURATION) {
+ stop_time =
+ (uint64_t) (USECS_PER_SEC * STD_LOOP_DURATION)
+ + get_current_time();
+ }
+
+ /*
+ * If doing delay each iteration, calcuate the number
+ * of clocks for each delay.
+ */
+ if (STD_LOOP_DELAY)
+ delay = USECS_PER_SEC * STD_LOOP_DELAY;
}
/*
- * If doing delay each iteration, calcuate the number
- * of clocks for each delay.
+ * if delay each iteration, loop for delay clocks.
+ * This will not be done on first iteration.
+ * The delay will happen before determining if
+ * there will be another iteration.
*/
- if (STD_LOOP_DELAY)
- delay = USECS_PER_SEC * STD_LOOP_DELAY;
- }
+ else if (STD_LOOP_DELAY) {
+ ct = get_current_time();
+ end = ct + delay;
+ while (ct < end) {
+ /*
+ * The following are special test hooks in the delay loop.
+ */
+ if (STD_LD_recfun) {
+ if (Debug)
+ printf
+ ("calling usc_recressive_func(0, %d, *STD_bigstack)\n",
+ STD_LD_recfun);
+ usc_recressive_func(0, STD_LD_recfun,
+ *STD_bigstack);
+ }
- /*
- * if delay each iteration, loop for delay clocks.
- * This will not be done on first iteration.
- * The delay will happen before determining if
- * there will be another iteration.
- */
- else if (STD_LOOP_DELAY) {
- ct = get_current_time();
- end = ct + delay;
- while (ct < end) {
- /*
- * The following are special test hooks in the delay loop.
- */
- if (STD_LD_recfun) {
+ ct = get_current_time();
+ }
+ }
+
+ if (STD_INFINITE)
+ keepgoing++;
+
+ if (STD_LOOP_COUNT && counter < STD_LOOP_COUNT)
+ keepgoing++;
+
+ if (STD_LOOP_DURATION != 0.0 && get_current_time() < stop_time)
+ keepgoing++;
+
+ if (keepgoing == 0)
+ return 0;
+
+ /*
+ * The following code allows special system testing hooks.
+ */
+
+ if (STD_LP_recfun) {
if (Debug)
- printf("calling usc_recressive_func(0, %d, *STD_bigstack)\n",
- STD_LD_recfun);
- usc_recressive_func(0, STD_LD_recfun, *STD_bigstack);
- }
-
- ct=get_current_time();
+ printf
+ ("calling usc_recressive_func(0, %d, *STD_bigstack)\n",
+ STD_LP_recfun);
+ usc_recressive_func(0, STD_LP_recfun, *STD_bigstack);
}
- }
-
- if (STD_INFINITE)
- keepgoing++;
-
- if (STD_LOOP_COUNT && counter < STD_LOOP_COUNT)
- keepgoing++;
-
- if (STD_LOOP_DURATION != 0.0 && get_current_time() < stop_time)
- keepgoing++;
-
- if (keepgoing == 0)
- return 0;
-
- /*
- * The following code allows special system testing hooks.
- */
-
- if (STD_LP_recfun) {
- if (Debug)
- printf("calling usc_recressive_func(0, %d, *STD_bigstack)\n",
- STD_LP_recfun);
- usc_recressive_func(0, STD_LP_recfun, *STD_bigstack);
- }
-
#if !defined(UCLINUX)
- if (STD_LP_sbrk) {
- if (Debug)
- printf("about to do sbrk(%d)\n", STD_LP_sbrk);
- sbrk(STD_LP_sbrk);
- }
+ if (STD_LP_sbrk) {
+ if (Debug)
+ printf("about to do sbrk(%d)\n", STD_LP_sbrk);
+ sbrk(STD_LP_sbrk);
+ }
#endif
-
- if (keepgoing)
- return 1;
- else
- return 0; /* done - stop iterating */
+ if (keepgoing)
+ return 1;
+ else
+ return 0; /* done - stop iterating */
}
-
/*
* This function recressively calls itself max times.
*/
static void usc_recressive_func(int cnt, int max, struct usc_bigstack_t bstack)
{
- if (cnt < max)
- usc_recressive_func(cnt+1, max, bstack);
+ if (cnt < max)
+ usc_recressive_func(cnt + 1, max, bstack);
}
@@ -823,42 +851,41 @@
/* for test specific parse_opts options */
option_t Options[] = {
- { "help", &Help2, NULL }, /* -help option */
- { "h", &Help, NULL }, /* -h option */
+ {"help", &Help2, NULL}, /* -help option */
+ {"h", &Help, NULL}, /* -h option */
#if INVALID_TEST_CASES
- { "missingflag", NULL, &ptr }, /* error */
- { "missingarg:", &Help, NULL }, /* error */
-#endif /* INVALID_TEST_CASES */
+ {"missingflag", NULL, &ptr}, /* error */
+ {"missingarg:", &Help, NULL}, /* error */
+#endif /* INVALID_TEST_CASES */
- { NULL, NULL, NULL }
+ {NULL, NULL, NULL}
};
int main(int argc, char **argv)
{
- int lc;
- char *msg;
- struct timeval t;
- int cnt;
+ int lc;
+ char *msg;
+ struct timeval t;
+ int cnt;
- if ((msg = parse_opts(argc, argv, Options, NULL)) != NULL) {
- printf("ERROR: %s\n", msg);
- exit(1);
- }
+ if ((msg = parse_opts(argc, argv, Options, NULL)) != NULL) {
+ printf("ERROR: %s\n", msg);
+ exit(1);
+ }
- TEST_PAUSE;
+ TEST_PAUSE;
- for (lc = 0; TEST_LOOPING(lc); lc++) {
+ for (lc = 0; TEST_LOOPING(lc); lc++) {
- TEST(gettimeofday(&t, NULL));
- printf("iter=%d: sec:%d, usec:%6.6d %s", lc+1, t.tv_sec,
- t.tv_usec, ctime(&t.tv_sec));
- }
+ TEST(gettimeofday(&t, NULL));
+ printf("iter=%d: sec:%d, usec:%6.6d %s", lc + 1, t.tv_sec,
+ t.tv_usec, ctime(&t.tv_sec));
+ }
+ TEST_CLEANUP;
- TEST_CLEANUP;
-
- exit(0);
+ exit(0);
}
#endif /* UNIT_TEST */
diff --git a/lib/pattern.c b/lib/pattern.c
index c507cbb..5863965 100644
--- a/lib/pattern.c
+++ b/lib/pattern.c
@@ -37,132 +37,130 @@
* with/against a known pattern.
*/
-int
-pattern_check(buf, buflen, pat, patlen, patshift)
-char *buf;
-int buflen;
-char *pat;
-int patlen;
-int patshift;
+int pattern_check(buf, buflen, pat, patlen, patshift)
+char *buf;
+int buflen;
+char *pat;
+int patlen;
+int patshift;
{
- int nb, ncmp, nleft;
- char *cp;
+ int nb, ncmp, nleft;
+ char *cp;
- if (patlen)
- patshift = patshift % patlen;
+ if (patlen)
+ patshift = patshift % patlen;
- cp = buf;
- nleft = buflen;
+ cp = buf;
+ nleft = buflen;
- /*
- * The following 2 blocks of code are to compare the first patlen
- * bytes of buf. We need 2 checks if patshift is > 0 since we
- * must check the last (patlen - patshift) bytes, and then the
- * first (patshift) bytes.
- */
+ /*
+ * The following 2 blocks of code are to compare the first patlen
+ * bytes of buf. We need 2 checks if patshift is > 0 since we
+ * must check the last (patlen - patshift) bytes, and then the
+ * first (patshift) bytes.
+ */
- nb = patlen - patshift;
- if (nleft < nb) {
- return (memcmp(cp, pat + patshift, nleft) ? -1 : 0);
- } else {
- if (memcmp(cp, pat + patshift, nb))
- return -1;
-
- nleft -= nb;
- cp += nb;
- }
-
- if (patshift > 0) {
- nb = patshift;
+ nb = patlen - patshift;
if (nleft < nb) {
- return (memcmp(cp, pat, nleft) ? -1 : 0);
+ return (memcmp(cp, pat + patshift, nleft) ? -1 : 0);
} else {
- if (memcmp(cp, pat, nb))
- return -1;
+ if (memcmp(cp, pat + patshift, nb))
+ return -1;
- nleft -= nb;
- cp += nb;
+ nleft -= nb;
+ cp += nb;
}
- }
- /*
- * Now, verify the rest of the buffer using the algorithm described
- * in the function header.
- */
+ if (patshift > 0) {
+ nb = patshift;
+ if (nleft < nb) {
+ return (memcmp(cp, pat, nleft) ? -1 : 0);
+ } else {
+ if (memcmp(cp, pat, nb))
+ return -1;
- ncmp = cp - buf;
- while (ncmp < buflen) {
- nb = (ncmp < nleft) ? ncmp : nleft;
- if (memcmp(buf, cp, nb))
- return -1;
+ nleft -= nb;
+ cp += nb;
+ }
+ }
- cp += nb;
- ncmp += nb;
- nleft -= nb;
- }
+ /*
+ * Now, verify the rest of the buffer using the algorithm described
+ * in the function header.
+ */
- return 0;
+ ncmp = cp - buf;
+ while (ncmp < buflen) {
+ nb = (ncmp < nleft) ? ncmp : nleft;
+ if (memcmp(buf, cp, nb))
+ return -1;
+
+ cp += nb;
+ ncmp += nb;
+ nleft -= nb;
+ }
+
+ return 0;
}
-int
-pattern_fill(buf, buflen, pat, patlen, patshift)
-char *buf;
-int buflen;
-char *pat;
-int patlen;
-int patshift;
+int pattern_fill(buf, buflen, pat, patlen, patshift)
+char *buf;
+int buflen;
+char *pat;
+int patlen;
+int patshift;
{
- int trans, ncopied, nleft;
- char *cp;
+ int trans, ncopied, nleft;
+ char *cp;
- if (patlen)
- patshift = patshift % patlen;
+ if (patlen)
+ patshift = patshift % patlen;
- cp = buf;
- nleft = buflen;
+ cp = buf;
+ nleft = buflen;
- /*
- * The following 2 blocks of code are to fill the first patlen
- * bytes of buf. We need 2 sections if patshift is > 0 since we
- * must first copy the last (patlen - patshift) bytes into buf[0]...,
- * and then the first (patshift) bytes of pattern following them.
- */
+ /*
+ * The following 2 blocks of code are to fill the first patlen
+ * bytes of buf. We need 2 sections if patshift is > 0 since we
+ * must first copy the last (patlen - patshift) bytes into buf[0]...,
+ * and then the first (patshift) bytes of pattern following them.
+ */
- trans = patlen - patshift;
- if (nleft < trans) {
- memcpy(cp, pat + patshift, nleft);
- return 0;
- } else {
- memcpy(cp, pat + patshift, trans);
- nleft -= trans;
- cp += trans;
- }
-
- if (patshift > 0) {
- trans = patshift;
+ trans = patlen - patshift;
if (nleft < trans) {
- memcpy(cp, pat, nleft);
- return 0;
+ memcpy(cp, pat + patshift, nleft);
+ return 0;
} else {
- memcpy(cp, pat, trans);
- nleft -= trans;
- cp += trans;
+ memcpy(cp, pat + patshift, trans);
+ nleft -= trans;
+ cp += trans;
}
- }
- /*
- * Now, fill the rest of the buffer using the algorithm described
- * in the function header comment.
- */
+ if (patshift > 0) {
+ trans = patshift;
+ if (nleft < trans) {
+ memcpy(cp, pat, nleft);
+ return 0;
+ } else {
+ memcpy(cp, pat, trans);
+ nleft -= trans;
+ cp += trans;
+ }
+ }
- ncopied = cp - buf;
- while (ncopied < buflen) {
- trans = (ncopied < nleft) ? ncopied : nleft;
- memcpy(cp, buf, trans);
- cp += trans;
- ncopied += trans;
- nleft -= trans;
- }
+ /*
+ * Now, fill the rest of the buffer using the algorithm described
+ * in the function header comment.
+ */
- return(0);
+ ncopied = cp - buf;
+ while (ncopied < buflen) {
+ trans = (ncopied < nleft) ? ncopied : nleft;
+ memcpy(cp, buf, trans);
+ cp += trans;
+ ncopied += trans;
+ nleft -= trans;
+ }
+
+ return (0);
}
diff --git a/lib/random_range.c b/lib/random_range.c
index 3376e6a..cd2096c 100644
--- a/lib/random_range.c
+++ b/lib/random_range.c
@@ -40,9 +40,9 @@
*/
struct range {
- int min;
- int max;
- int mult;
+ int min;
+ int max;
+ int mult;
};
/*
@@ -95,23 +95,22 @@
* parse_range() returns -1 on error, or the number of ranges parsed.
*/
-static int str_to_int();
+static int str_to_int();
static long long divider(long long, long long, long long, long long);
-int
-parse_ranges(str, defmin, defmax, defmult, parse_func, rangeptr, errptr)
-char *str;
-int defmin;
-int defmax;
-int defmult;
-int (*parse_func)();
-char **rangeptr;
-char **errptr;
+int parse_ranges(str, defmin, defmax, defmult, parse_func, rangeptr, errptr)
+char *str;
+int defmin;
+int defmax;
+int defmult;
+int (*parse_func) ();
+char **rangeptr;
+char **errptr;
{
- int ncommas;
- char *tmpstr, *cp, *tok, *n1str, *n2str, *multstr;
- struct range *rp, *ranges;
- static char errmsg[256];
+ int ncommas;
+ char *tmpstr, *cp, *tok, *n1str, *n2str, *multstr;
+ struct range *rp, *ranges;
+ static char errmsg[256];
if (errptr != NULL) {
*errptr = errmsg;
@@ -128,7 +127,7 @@
}
tmpstr = strdup(str);
- ranges = (struct range *)malloc((ncommas+1) * sizeof(struct range));
+ ranges = (struct range *)malloc((ncommas + 1) * sizeof(struct range));
rp = ranges;
tok = strtok(tmpstr, ",");
@@ -143,11 +142,11 @@
if ((cp = strchr(n1str, ':')) != NULL) {
*cp = '\0';
- n2str = cp+1;
+ n2str = cp + 1;
if ((cp = strchr(n2str, ':')) != NULL) {
*cp = '\0';
- multstr = cp+1;
+ multstr = cp + 1;
}
}
@@ -158,8 +157,10 @@
*/
if ((int)strlen(n1str) > 0) {
- if ((*parse_func)(n1str, &rp->min) < 0) {
- sprintf(errmsg, "error parsing string %s into an integer", n1str);
+ if ((*parse_func) (n1str, &rp->min) < 0) {
+ sprintf(errmsg,
+ "error parsing string %s into an integer",
+ n1str);
free(tmpstr);
free(ranges);
return -1;
@@ -176,8 +177,10 @@
if (n2str == NULL) {
rp->max = rp->min;
} else if ((int)strlen(n2str) > 0) {
- if ((*parse_func)(n2str, &rp->max) < 0) {
- sprintf(errmsg, "error parsing string %s into an integer", n2str);
+ if ((*parse_func) (n2str, &rp->max) < 0) {
+ sprintf(errmsg,
+ "error parsing string %s into an integer",
+ n2str);
free(tmpstr);
free(ranges);
return -1;
@@ -192,8 +195,10 @@
*/
if (multstr != NULL && (int)strlen(multstr) > 0) {
- if ((*parse_func)(multstr, &rp->mult) < 0) {
- sprintf(errmsg, "error parsing string %s into an integer", multstr);
+ if ((*parse_func) (multstr, &rp->mult) < 0) {
+ sprintf(errmsg,
+ "error parsing string %s into an integer",
+ multstr);
free(tmpstr);
free(ranges);
return -1;
@@ -209,7 +214,7 @@
if (rangeptr != NULL) {
*rangeptr = (char *)ranges;
} else {
- free(ranges); /* just running in parse mode */
+ free(ranges); /* just running in parse mode */
}
return (rp - ranges);
@@ -219,12 +224,11 @@
* The default integer-parsing function
*/
-static int
-str_to_int(str, ip)
-char *str;
-int *ip;
+static int str_to_int(str, ip)
+char *str;
+int *ip;
{
- char c;
+ char c;
if (sscanf(str, "%i%c", ip, &c) != 1) {
return -1;
@@ -239,26 +243,23 @@
* and that r is a valid range within that buffer.
*/
-int
-range_min(rbuf, r)
-char *rbuf;
-int r;
+int range_min(rbuf, r)
+char *rbuf;
+int r;
{
return ((struct range *)rbuf)[r].min;
}
-int
-range_max(rbuf, r)
-char *rbuf;
-int r;
+int range_max(rbuf, r)
+char *rbuf;
+int r;
{
return ((struct range *)rbuf)[r].max;
}
-int
-range_mult(rbuf, r)
-char *rbuf;
-int r;
+int range_mult(rbuf, r)
+char *rbuf;
+int r;
{
return ((struct range *)rbuf)[r].mult;
}
@@ -288,16 +289,15 @@
* setting the seed.
*****************************************************************************/
-long
-random_range(min, max, mult, errp)
-int min;
-int max;
-int mult;
-char **errp;
+long random_range(min, max, mult, errp)
+int min;
+int max;
+int mult;
+char **errp;
{
- int r, nmults, orig_min, orig_max, orig_mult, tmp;
- extern long lrand48();
- static char errbuf[128];
+ int r, nmults, orig_min, orig_max, orig_mult, tmp;
+ extern long lrand48();
+ static char errbuf[128];
/*
* Sanity check
@@ -333,44 +333,46 @@
* select the random number
*/
- if ((r = min % mult)) /* bump to the next higher 'mult' multiple */
- min += mult - r;
+ if ((r = min % mult)) /* bump to the next higher 'mult' multiple */
+ min += mult - r;
- if ((r = max % mult)) /* reduce to the next lower 'mult' multiple */
- max -= r;
+ if ((r = max % mult)) /* reduce to the next lower 'mult' multiple */
+ max -= r;
- if (min > max) { /* no 'mult' multiples between min & max */
+ if (min > max) { /* no 'mult' multiples between min & max */
if (errp != NULL) {
- sprintf(errbuf, "no numbers in the range %d:%d that are a multiple of %d", orig_min, orig_max, orig_mult);
+ sprintf(errbuf,
+ "no numbers in the range %d:%d that are a multiple of %d",
+ orig_min, orig_max, orig_mult);
*errp = errbuf;
}
- return -1;
+ return -1;
}
if (errp != NULL) {
*errp = NULL;
}
- nmults = ((max - min) / mult) + 1;
+ nmults = ((max - min) / mult) + 1;
#if CRAY
- /*
- * If max is less than 2gb, then the value can fit in 32 bits
- * and the standard lrand48() routine can be used.
- */
- if (max <= (long)2147483647) {
- return (long) (min + (((long)lrand48() % nmults) * mult));
- } else {
- /*
- * max is greater than 2gb - meeds more than 32 bits.
- * Since lrand48 only will get a number up to 32bits.
- */
- long randnum;
- randnum=divider(min, max, 0, -1);
- return (long) (min + ((randnum % nmults) * mult));
- }
+ /*
+ * If max is less than 2gb, then the value can fit in 32 bits
+ * and the standard lrand48() routine can be used.
+ */
+ if (max <= (long)2147483647) {
+ return (long)(min + (((long)lrand48() % nmults) * mult));
+ } else {
+ /*
+ * max is greater than 2gb - meeds more than 32 bits.
+ * Since lrand48 only will get a number up to 32bits.
+ */
+ long randnum;
+ randnum = divider(min, max, 0, -1);
+ return (long)(min + ((randnum % nmults) * mult));
+ }
#else
- return (min + ((lrand48() % nmults) * mult));
+ return (min + ((lrand48() % nmults) * mult));
#endif
}
@@ -378,16 +380,15 @@
/*
* Just like random_range, but all values are longs.
*/
-long
-random_rangel(min, max, mult, errp)
-long min;
-long max;
-long mult;
-char **errp;
+long random_rangel(min, max, mult, errp)
+long min;
+long max;
+long mult;
+char **errp;
{
- long r, nmults, orig_min, orig_max, orig_mult, tmp;
- extern long lrand48();
- static char errbuf[128];
+ long r, nmults, orig_min, orig_max, orig_mult, tmp;
+ extern long lrand48();
+ static char errbuf[128];
/*
* Sanity check
@@ -423,63 +424,62 @@
* select the random number
*/
- if ((r = min % mult)) /* bump to the next higher 'mult' multiple */
- min += mult - r;
+ if ((r = min % mult)) /* bump to the next higher 'mult' multiple */
+ min += mult - r;
- if ((r = max % mult)) /* reduce to the next lower 'mult' multiple */
- max -= r;
+ if ((r = max % mult)) /* reduce to the next lower 'mult' multiple */
+ max -= r;
- if (min > max) { /* no 'mult' multiples between min & max */
+ if (min > max) { /* no 'mult' multiples between min & max */
if (errp != NULL) {
- sprintf(errbuf,
- "no numbers in the range %ld:%ld that are a multiple of %ld",
- orig_min, orig_max, orig_mult);
- *errp = errbuf;
+ sprintf(errbuf,
+ "no numbers in the range %ld:%ld that are a multiple of %ld",
+ orig_min, orig_max, orig_mult);
+ *errp = errbuf;
}
- return -1;
+ return -1;
}
if (errp != NULL) {
*errp = NULL;
}
- nmults = ((max - min) / mult) + 1;
+ nmults = ((max - min) / mult) + 1;
#if CRAY || (_MIPS_SZLONG == 64)
- /*
- * If max is less than 2gb, then the value can fit in 32 bits
- * and the standard lrand48() routine can be used.
- */
- if (max <= (long)2147483647) {
- return (long) (min + (((long)lrand48() % nmults) * mult));
- } else {
- /*
- * max is greater than 2gb - meeds more than 32 bits.
- * Since lrand48 only will get a number up to 32bits.
- */
- long randnum;
- randnum=divider(min, max, 0, -1);
- return (long) (min + ((randnum % nmults) * mult));
- }
+ /*
+ * If max is less than 2gb, then the value can fit in 32 bits
+ * and the standard lrand48() routine can be used.
+ */
+ if (max <= (long)2147483647) {
+ return (long)(min + (((long)lrand48() % nmults) * mult));
+ } else {
+ /*
+ * max is greater than 2gb - meeds more than 32 bits.
+ * Since lrand48 only will get a number up to 32bits.
+ */
+ long randnum;
+ randnum = divider(min, max, 0, -1);
+ return (long)(min + ((randnum % nmults) * mult));
+ }
#else
- return (min + ((lrand48() % nmults) * mult));
+ return (min + ((lrand48() % nmults) * mult));
#endif
}
/*
* Attempts to be just like random_range, but everything is long long (64 bit)
*/
-long long
-random_rangell(min, max, mult, errp)
-long long min;
-long long max;
-long long mult;
-char **errp;
+long long random_rangell(min, max, mult, errp)
+long long min;
+long long max;
+long long mult;
+char **errp;
{
- long long r, nmults, orig_min, orig_max, orig_mult, tmp;
- long long randnum;
- extern long lrand48();
- static char errbuf[128];
+ long long r, nmults, orig_min, orig_max, orig_mult, tmp;
+ long long randnum;
+ extern long lrand48();
+ static char errbuf[128];
/*
* Sanity check
@@ -515,41 +515,42 @@
* select the random number
*/
- if ((r = min % mult)) /* bump to the next higher 'mult' multiple */
- min += mult - r;
+ if ((r = min % mult)) /* bump to the next higher 'mult' multiple */
+ min += mult - r;
- if ((r = max % mult)) /* reduce to the next lower 'mult' multiple */
- max -= r;
+ if ((r = max % mult)) /* reduce to the next lower 'mult' multiple */
+ max -= r;
- if (min > max) { /* no 'mult' multiples between min & max */
+ if (min > max) { /* no 'mult' multiples between min & max */
if (errp != NULL) {
- sprintf(errbuf,
- "no numbers in the range %lld:%lld that are a multiple of %lld",
- orig_min, orig_max, orig_mult);
- *errp = errbuf;
+ sprintf(errbuf,
+ "no numbers in the range %lld:%lld that are a multiple of %lld",
+ orig_min, orig_max, orig_mult);
+ *errp = errbuf;
}
- return -1;
+ return -1;
}
if (errp != NULL) {
*errp = NULL;
}
- nmults = ((max - min) / mult) + 1;
- /*
+ nmults = ((max - min) / mult) + 1;
+ /*
* If max is less than 2gb, then the value can fit in 32 bits
* and the standard lrand48() routine can be used.
*/
if (max <= (long)2147483647) {
- return (long long) (min + (((long long)lrand48() % nmults) * mult));
+ return (long long)(min +
+ (((long long)lrand48() % nmults) * mult));
} else {
- /*
- * max is greater than 2gb - meeds more than 32 bits.
- * Since lrand48 only will get a number up to 32bits.
- */
- randnum=divider(min, max, 0, -1);
- return (long long) (min + ((randnum % nmults) * mult));
- }
+ /*
+ * max is greater than 2gb - meeds more than 32 bits.
+ * Since lrand48 only will get a number up to 32bits.
+ */
+ randnum = divider(min, max, 0, -1);
+ return (long long)(min + ((randnum % nmults) * mult));
+ }
}
@@ -570,62 +571,62 @@
static long long
divider(long long min, long long max, long long cnt, long long rand)
{
- long long med, half, diff;
+ long long med, half, diff;
- /*
- * prevent run away code. We are dividing by two each count.
- * if we get to a count of more than 32, we should have gotten
- * to 2gb.
- */
- if (cnt > 32)
- return -1;
+ /*
+ * prevent run away code. We are dividing by two each count.
+ * if we get to a count of more than 32, we should have gotten
+ * to 2gb.
+ */
+ if (cnt > 32)
+ return -1;
- /*
- * Only get a random number the first time.
- */
- if (cnt == 0 || rand < -1) {
- rand = (long long)lrand48(); /* 32 bit random number */
- }
-
- diff = max - min;
-
- if (diff <= 2147483647)
- return min + rand;
-
- half = diff/(long long)2; /* half the distance between min and max */
- med = min + half; /* med way point between min and max */
-
-#if DEBUG
-printf("divider: min=%lld, max=%lld, cnt=%lld, rand=%lld\n", min, max, cnt, rand);
-printf(" diff = %lld, half = %lld, med = %lld\n", diff, half, med);
-#endif
-
- if (half <= 2147483647) {
- /*
- * If half is smaller than 2gb, we can use the random number
- * to pick the number within the min to med or med to max
- * if the cnt bit of rand is zero or one, respectively.
- */
- if (rand & (1<<cnt))
- return med + rand;
- else
- return min + rand;
- } else {
- /*
- * recursively call ourself to reduce the value to the bottom half
- * or top half (bit cnt is set).
- */
- if (rand & (1<<cnt)) {
- return divider(med, max, cnt+1, rand);
- } else {
- return divider(min, med, cnt+1, rand);
+ /*
+ * Only get a random number the first time.
+ */
+ if (cnt == 0 || rand < -1) {
+ rand = (long long)lrand48(); /* 32 bit random number */
}
- }
+ diff = max - min;
+
+ if (diff <= 2147483647)
+ return min + rand;
+
+ half = diff / (long long)2; /* half the distance between min and max */
+ med = min + half; /* med way point between min and max */
+
+#if DEBUG
+ printf("divider: min=%lld, max=%lld, cnt=%lld, rand=%lld\n", min, max,
+ cnt, rand);
+ printf(" diff = %lld, half = %lld, med = %lld\n", diff, half, med);
+#endif
+
+ if (half <= 2147483647) {
+ /*
+ * If half is smaller than 2gb, we can use the random number
+ * to pick the number within the min to med or med to max
+ * if the cnt bit of rand is zero or one, respectively.
+ */
+ if (rand & (1 << cnt))
+ return med + rand;
+ else
+ return min + rand;
+ } else {
+ /*
+ * recursively call ourself to reduce the value to the bottom half
+ * or top half (bit cnt is set).
+ */
+ if (rand & (1 << cnt)) {
+ return divider(med, max, cnt + 1, rand);
+ } else {
+ return divider(min, med, cnt + 1, rand);
+ }
+
+ }
}
-
/*****************************************************************************
* random_range_seed(s)
*
@@ -633,13 +634,12 @@
* be used in random_range().
*****************************************************************************/
-void
-random_range_seed(s)
-long s;
+void random_range_seed(s)
+long s;
{
- extern void srand48();
+ extern void srand48();
- srand48(s);
+ srand48(s);
}
/****************************************************************************
@@ -649,57 +649,55 @@
* set in mask. If mask is zero, zero is returned.
*
****************************************************************************/
-long
-random_bit(long mask)
+long random_bit(long mask)
{
- int nbits = 0; /* number of set bits in mask */
- long bit; /* used to count bits and num of set bits choosen */
- int nshift; /* used to count bit shifts */
+ int nbits = 0; /* number of set bits in mask */
+ long bit; /* used to count bits and num of set bits choosen */
+ int nshift; /* used to count bit shifts */
- if (mask == 0)
- return 0;
+ if (mask == 0)
+ return 0;
- /*
- * get the number of bits set in mask
- */
+ /*
+ * get the number of bits set in mask
+ */
#ifndef CRAY
- bit=1L;
- for (nshift=0; (unsigned int)nshift<sizeof(long)*8; nshift++) {
- if (mask & bit)
- nbits++;
- bit=bit<<1;
- }
+ bit = 1L;
+ for (nshift = 0; (unsigned int)nshift < sizeof(long) * 8; nshift++) {
+ if (mask & bit)
+ nbits++;
+ bit = bit << 1;
+ }
#else
- nbits=_popcnt(mask);
-#endif /* if CRAY */
+ nbits = _popcnt(mask);
+#endif /* if CRAY */
- /*
- * randomly choose a bit.
- */
- bit=random_range(1, nbits, 1, NULL);
+ /*
+ * randomly choose a bit.
+ */
+ bit = random_range(1, nbits, 1, NULL);
- /*
- * shift bits until you determine which bit was randomly choosen.
- * nshift will hold the number of shifts to make.
- */
+ /*
+ * shift bits until you determine which bit was randomly choosen.
+ * nshift will hold the number of shifts to make.
+ */
- nshift=0;
- while (bit) {
- /* check if the current one's bit is set */
- if (mask & 1L) {
- bit--;
- }
- mask = mask >> 1;
- nshift++;
- }
+ nshift = 0;
+ while (bit) {
+ /* check if the current one's bit is set */
+ if (mask & 1L) {
+ bit--;
+ }
+ mask = mask >> 1;
+ nshift++;
+ }
- return 01L << (nshift-1);
+ return 01L << (nshift - 1);
}
-
#if RANDOM_BIT_UNITTEST
/*
* The following is a unit test main function for random_bit().
@@ -708,210 +706,213 @@
int argc;
char **argv;
{
- int ind;
- int cnt, iter;
- long mask, ret;
+ int ind;
+ int cnt, iter;
+ long mask, ret;
- printf("test for first and last bit set\n");
- mask=1L;
- ret=random_bit(mask);
- printf("random_bit(%#o) returned %#o\n", mask, ret);
+ printf("test for first and last bit set\n");
+ mask = 1L;
+ ret = random_bit(mask);
+ printf("random_bit(%#o) returned %#o\n", mask, ret);
- mask=1L<<(sizeof(long)*8-1);
- ret=random_bit(mask);
- printf("random_bit(%#o) returned %#o\n", mask, ret);
+ mask = 1L << (sizeof(long) * 8 - 1);
+ ret = random_bit(mask);
+ printf("random_bit(%#o) returned %#o\n", mask, ret);
- if (argc >= 3) {
- iter=atoi(argv[1]);
- for (ind=2; ind<argc; ind++) {
- printf("Calling random_bit %d times for mask %#o\n", iter, mask);
- sscanf(argv[ind], "%i", &mask);
- for (cnt=0; cnt<iter; cnt++) {
- ret=random_bit(mask);
- printf("random_bit(%#o) returned %#o\n", mask, ret);
- }
- }
- }
- exit(0);
+ if (argc >= 3) {
+ iter = atoi(argv[1]);
+ for (ind = 2; ind < argc; ind++) {
+ printf("Calling random_bit %d times for mask %#o\n",
+ iter, mask);
+ sscanf(argv[ind], "%i", &mask);
+ for (cnt = 0; cnt < iter; cnt++) {
+ ret = random_bit(mask);
+ printf("random_bit(%#o) returned %#o\n", mask,
+ ret);
+ }
+ }
+ }
+ exit(0);
}
#endif /* end if RANDOM_BIT_UNITTEST */
-
#if UNIT_TEST
/*
* The following is a unit test main function for random_range*().
*/
-#define PARTNUM 10 /* used to determine even distribution of random numbers */
+#define PARTNUM 10 /* used to determine even distribution of random numbers */
#define MEG 1024*1024*1024
#define GIG 1073741824
-int
-main(argc, argv)
+int main(argc, argv)
int argc;
char **argv;
{
- int ind;
- int cnt, iter=10;
- int imin=0, imult=1, itmin, itmax=0;
+ int ind;
+ int cnt, iter = 10;
+ int imin = 0, imult = 1, itmin, itmax = 0;
#if CRAY
- int imax=6*GIG; /* higher than 32 bits */
+ int imax = 6 * GIG; /* higher than 32 bits */
#else
- int imax=1048576;
+ int imax = 1048576;
#endif
- long lret, lmin=0, lmult=1, ltmin, ltmax=0;
+ long lret, lmin = 0, lmult = 1, ltmin, ltmax = 0;
#if CRAY || (_MIPS_SZLONG == 64)
- long lmax=6*(long)GIG; /* higher than 32 bits */
+ long lmax = 6 * (long)GIG; /* higher than 32 bits */
#else
- long lmax=1048576;
+ long lmax = 1048576;
#endif
- long long llret, llmin=0, llmult=1, lltmin, lltmax=0;
- long long llmax=(long long)80*(long long)GIG;
+ long long llret, llmin = 0, llmult = 1, lltmin, lltmax = 0;
+ long long llmax = (long long)80 * (long long)GIG;
- long part;
- long long lpart;
- long cntarr[PARTNUM];
- long valbound[PARTNUM];
- long long lvalbound[PARTNUM];
+ long part;
+ long long lpart;
+ long cntarr[PARTNUM];
+ long valbound[PARTNUM];
+ long long lvalbound[PARTNUM];
- for (ind=0; ind<PARTNUM; ind++)
- cntarr[ind]=0;
+ for (ind = 0; ind < PARTNUM; ind++)
+ cntarr[ind] = 0;
- if (argc < 2) {
- printf("Usage: %s func [iterations] \n", argv[0]);
- printf("func can be random_range, random_rangel, random_rangell\n");
- exit(1);
- }
+ if (argc < 2) {
+ printf("Usage: %s func [iterations] \n", argv[0]);
+ printf
+ ("func can be random_range, random_rangel, random_rangell\n");
+ exit(1);
+ }
- if (argc >= 3) {
- if (sscanf(argv[2], "%i", &iter) != 1) {
- printf("Usage: %s [func iterations] \n", argv[0]);
- printf("argv[2] is not a number\n");
- exit(1);
- }
- }
-
-
- /*
- * random_rangel ()
- */
- if (strcmp(argv[1], "random_rangel") == 0) {
- ltmin=lmax;
- part = lmax/PARTNUM;
- for (ind=0; ind<PARTNUM; ind++) {
- valbound[ind]=part*ind;
- }
-
- for (cnt=0; cnt<iter; cnt++) {
- lret=random_rangel(lmin, lmax, lmult, NULL);
- if (iter < 100)
- printf("%ld\n", lret);
- if (lret < ltmin)
- ltmin = lret;
- if (lret > ltmax)
- ltmax = lret;
- for (ind=0; ind<PARTNUM-1; ind++) {
- if (valbound[ind] < lret && lret <= valbound[ind+1]) {
- cntarr[ind]++;
- break;
+ if (argc >= 3) {
+ if (sscanf(argv[2], "%i", &iter) != 1) {
+ printf("Usage: %s [func iterations] \n", argv[0]);
+ printf("argv[2] is not a number\n");
+ exit(1);
}
- }
- if (lret > valbound[PARTNUM-1]) {
- cntarr[PARTNUM-1]++;
- }
- }
- for (ind=0; ind<PARTNUM-1; ind++) {
- printf("%2d %-13ld to %-13ld %5ld %4.4f\n", ind+1,
- valbound[ind], valbound[ind+1], cntarr[ind],
- (float)(cntarr[ind]/(float)iter));
- }
- printf("%2d %-13ld to %-13ld %5ld %4.4f\n", PARTNUM,
- valbound[PARTNUM-1], lmax, cntarr[PARTNUM-1],
- (float)(cntarr[PARTNUM-1]/(float)iter));
- printf(" min=%ld, max=%ld\n", ltmin, ltmax);
+ }
- } else if (strcmp(argv[1], "random_rangell") == 0) {
- /*
- * random_rangell() unit test
- */
- lltmin=llmax;
- lpart = llmax/PARTNUM;
- for (ind=0; ind<PARTNUM; ind++) {
- lvalbound[ind]=(long long)(lpart*ind);
- }
-
- for (cnt=0; cnt<iter; cnt++) {
- llret=random_rangell(llmin, llmax, llmult, NULL);
- if (iter < 100)
- printf("random_rangell returned %lld\n", llret);
- if (llret < lltmin)
- lltmin = llret;
- if (llret > lltmax)
- lltmax = llret;
-
- for (ind=0; ind<PARTNUM-1; ind++) {
- if (lvalbound[ind] < llret && llret <= lvalbound[ind+1]) {
- cntarr[ind]++;
- break;
- }
- }
- if (llret > lvalbound[PARTNUM-1]) {
- cntarr[PARTNUM-1]++;
- }
- }
- for (ind=0; ind<PARTNUM-1; ind++) {
- printf("%2d %-13lld to %-13lld %5ld %4.4f\n", ind+1,
- lvalbound[ind], lvalbound[ind+1], cntarr[ind],
- (float)(cntarr[ind]/(float)iter));
- }
- printf("%2d %-13lld to %-13lld %5ld %4.4f\n", PARTNUM,
- lvalbound[PARTNUM-1], llmax, cntarr[PARTNUM-1],
- (float)(cntarr[PARTNUM-1]/(float)iter));
- printf(" min=%lld, max=%lld\n", lltmin, lltmax);
-
- } else {
/*
- * random_range() unit test
- */
- itmin=imax;
- part = imax/PARTNUM;
- for (ind=0; ind<PARTNUM; ind++) {
- valbound[ind]=part*ind;
- }
-
- for (cnt=0; cnt<iter; cnt++) {
- lret=random_range(imin, imax, imult, NULL);
- if (iter < 100)
- printf("%ld\n", lret);
- if (lret < itmin)
- itmin = lret;
- if (lret > itmax)
- itmax = lret;
-
- for (ind=0; ind<PARTNUM-1; ind++) {
- if (valbound[ind] < lret && lret <= valbound[ind+1]) {
- cntarr[ind]++;
- break;
+ * random_rangel ()
+ */
+ if (strcmp(argv[1], "random_rangel") == 0) {
+ ltmin = lmax;
+ part = lmax / PARTNUM;
+ for (ind = 0; ind < PARTNUM; ind++) {
+ valbound[ind] = part * ind;
}
- }
- if (lret > valbound[PARTNUM-1]) {
- cntarr[PARTNUM-1]++;
- }
- }
- for (ind=0; ind<PARTNUM-1; ind++) {
- printf("%2d %-13ld to %-13ld %5ld %4.4f\n", ind+1,
- valbound[ind], valbound[ind+1], cntarr[ind],
- (float)(cntarr[ind]/(float)iter));
- }
- printf("%2d %-13ld to %-13ld %5ld %4.4f\n", PARTNUM,
- valbound[PARTNUM-1], (long)imax, cntarr[PARTNUM-1],
- (float)(cntarr[PARTNUM-1]/(float)iter));
- printf(" min=%d, max=%d\n", itmin, itmax);
- }
+ for (cnt = 0; cnt < iter; cnt++) {
+ lret = random_rangel(lmin, lmax, lmult, NULL);
+ if (iter < 100)
+ printf("%ld\n", lret);
+ if (lret < ltmin)
+ ltmin = lret;
+ if (lret > ltmax)
+ ltmax = lret;
+ for (ind = 0; ind < PARTNUM - 1; ind++) {
+ if (valbound[ind] < lret
+ && lret <= valbound[ind + 1]) {
+ cntarr[ind]++;
+ break;
+ }
+ }
+ if (lret > valbound[PARTNUM - 1]) {
+ cntarr[PARTNUM - 1]++;
+ }
+ }
+ for (ind = 0; ind < PARTNUM - 1; ind++) {
+ printf("%2d %-13ld to %-13ld %5ld %4.4f\n", ind + 1,
+ valbound[ind], valbound[ind + 1], cntarr[ind],
+ (float)(cntarr[ind] / (float)iter));
+ }
+ printf("%2d %-13ld to %-13ld %5ld %4.4f\n", PARTNUM,
+ valbound[PARTNUM - 1], lmax, cntarr[PARTNUM - 1],
+ (float)(cntarr[PARTNUM - 1] / (float)iter));
+ printf(" min=%ld, max=%ld\n", ltmin, ltmax);
- exit(0);
+ } else if (strcmp(argv[1], "random_rangell") == 0) {
+ /*
+ * random_rangell() unit test
+ */
+ lltmin = llmax;
+ lpart = llmax / PARTNUM;
+ for (ind = 0; ind < PARTNUM; ind++) {
+ lvalbound[ind] = (long long)(lpart * ind);
+ }
+
+ for (cnt = 0; cnt < iter; cnt++) {
+ llret = random_rangell(llmin, llmax, llmult, NULL);
+ if (iter < 100)
+ printf("random_rangell returned %lld\n", llret);
+ if (llret < lltmin)
+ lltmin = llret;
+ if (llret > lltmax)
+ lltmax = llret;
+
+ for (ind = 0; ind < PARTNUM - 1; ind++) {
+ if (lvalbound[ind] < llret
+ && llret <= lvalbound[ind + 1]) {
+ cntarr[ind]++;
+ break;
+ }
+ }
+ if (llret > lvalbound[PARTNUM - 1]) {
+ cntarr[PARTNUM - 1]++;
+ }
+ }
+ for (ind = 0; ind < PARTNUM - 1; ind++) {
+ printf("%2d %-13lld to %-13lld %5ld %4.4f\n",
+ ind + 1, lvalbound[ind], lvalbound[ind + 1],
+ cntarr[ind], (float)(cntarr[ind] / (float)iter));
+ }
+ printf("%2d %-13lld to %-13lld %5ld %4.4f\n", PARTNUM,
+ lvalbound[PARTNUM - 1], llmax, cntarr[PARTNUM - 1],
+ (float)(cntarr[PARTNUM - 1] / (float)iter));
+ printf(" min=%lld, max=%lld\n", lltmin, lltmax);
+
+ } else {
+ /*
+ * random_range() unit test
+ */
+ itmin = imax;
+ part = imax / PARTNUM;
+ for (ind = 0; ind < PARTNUM; ind++) {
+ valbound[ind] = part * ind;
+ }
+
+ for (cnt = 0; cnt < iter; cnt++) {
+ lret = random_range(imin, imax, imult, NULL);
+ if (iter < 100)
+ printf("%ld\n", lret);
+ if (lret < itmin)
+ itmin = lret;
+ if (lret > itmax)
+ itmax = lret;
+
+ for (ind = 0; ind < PARTNUM - 1; ind++) {
+ if (valbound[ind] < lret
+ && lret <= valbound[ind + 1]) {
+ cntarr[ind]++;
+ break;
+ }
+ }
+ if (lret > valbound[PARTNUM - 1]) {
+ cntarr[PARTNUM - 1]++;
+ }
+ }
+ for (ind = 0; ind < PARTNUM - 1; ind++) {
+ printf("%2d %-13ld to %-13ld %5ld %4.4f\n", ind + 1,
+ valbound[ind], valbound[ind + 1], cntarr[ind],
+ (float)(cntarr[ind] / (float)iter));
+ }
+ printf("%2d %-13ld to %-13ld %5ld %4.4f\n", PARTNUM,
+ valbound[PARTNUM - 1], (long)imax, cntarr[PARTNUM - 1],
+ (float)(cntarr[PARTNUM - 1] / (float)iter));
+ printf(" min=%d, max=%d\n", itmin, itmax);
+
+ }
+
+ exit(0);
}
#endif
diff --git a/lib/rmobj.c b/lib/rmobj.c
index 980b5a2..9b6a643 100644
--- a/lib/rmobj.c
+++ b/lib/rmobj.c
@@ -77,135 +77,139 @@
* NULL) and return -1. Otherwise it will return 0.
*
************************************************************/
-#include <errno.h> /* for errno */
-#include <stdio.h> /* for NULL */
-#include <stdlib.h> /* for malloc() */
-#include <string.h> /* for string function */
-#include <limits.h> /* for PATH_MAX */
-#include <sys/types.h> /* for opendir(), readdir(), closedir(), stat() */
-#include <sys/stat.h> /* for [l]stat() */
-#include <dirent.h> /* for opendir(), readdir(), closedir() */
-#include <unistd.h> /* for rmdir(), unlink() */
+#include <errno.h> /* for errno */
+#include <stdio.h> /* for NULL */
+#include <stdlib.h> /* for malloc() */
+#include <string.h> /* for string function */
+#include <limits.h> /* for PATH_MAX */
+#include <sys/types.h> /* for opendir(), readdir(), closedir(), stat() */
+#include <sys/stat.h> /* for [l]stat() */
+#include <dirent.h> /* for opendir(), readdir(), closedir() */
+#include <unistd.h> /* for rmdir(), unlink() */
#include "rmobj.h"
#define SYSERR strerror(errno)
-int
-rmobj(char *obj, char **errmsg)
+int rmobj(char *obj, char **errmsg)
{
- int ret_val = 0; /* return value from this routine */
- DIR *dir; /* pointer to a directory */
- struct dirent *dir_ent; /* pointer to directory entries */
- char dirobj[PATH_MAX]; /* object inside directory to modify */
- struct stat statbuf; /* used to hold stat information */
- static char err_msg[1024]; /* error message */
+ int ret_val = 0; /* return value from this routine */
+ DIR *dir; /* pointer to a directory */
+ struct dirent *dir_ent; /* pointer to directory entries */
+ char dirobj[PATH_MAX]; /* object inside directory to modify */
+ struct stat statbuf; /* used to hold stat information */
+ static char err_msg[1024]; /* error message */
- /* Determine the file type */
- if (lstat(obj, &statbuf) < 0) {
- if (errmsg != NULL) {
- sprintf(err_msg, "lstat(%s) failed; errno=%d: %s",
- obj, errno, SYSERR);
- *errmsg = err_msg;
- }
- return -1;
- }
+ /* Determine the file type */
+ if (lstat(obj, &statbuf) < 0) {
+ if (errmsg != NULL) {
+ sprintf(err_msg, "lstat(%s) failed; errno=%d: %s",
+ obj, errno, SYSERR);
+ *errmsg = err_msg;
+ }
+ return -1;
+ }
- /* Take appropriate action, depending on the file type */
- if ((statbuf.st_mode & S_IFMT) == S_IFDIR) {
- /* object is a directory */
+ /* Take appropriate action, depending on the file type */
+ if ((statbuf.st_mode & S_IFMT) == S_IFDIR) {
+ /* object is a directory */
- /* Do NOT perform the request if the directory is "/" */
- if (!strcmp(obj, "/")) {
- if (errmsg != NULL) {
- sprintf(err_msg, "Cannot remove /");
- *errmsg = err_msg;
- }
- return -1;
- }
+ /* Do NOT perform the request if the directory is "/" */
+ if (!strcmp(obj, "/")) {
+ if (errmsg != NULL) {
+ sprintf(err_msg, "Cannot remove /");
+ *errmsg = err_msg;
+ }
+ return -1;
+ }
- /* Open the directory to get access to what is in it */
- if ((dir = opendir(obj)) == NULL) {
- if (rmdir(obj) != 0) {
- if (errmsg != NULL) {
- sprintf(err_msg, "rmdir(%s) failed; errno=%d: %s",
- obj, errno, SYSERR);
- *errmsg = err_msg;
- }
- return -1;
- } else {
- return 0;
- }
- }
+ /* Open the directory to get access to what is in it */
+ if ((dir = opendir(obj)) == NULL) {
+ if (rmdir(obj) != 0) {
+ if (errmsg != NULL) {
+ sprintf(err_msg,
+ "rmdir(%s) failed; errno=%d: %s",
+ obj, errno, SYSERR);
+ *errmsg = err_msg;
+ }
+ return -1;
+ } else {
+ return 0;
+ }
+ }
- /* Loop through the entries in the directory, removing each one */
- for (dir_ent = (struct dirent *)readdir(dir);
- dir_ent != NULL;
- dir_ent = (struct dirent *)readdir(dir)) {
+ /* Loop through the entries in the directory, removing each one */
+ for (dir_ent = (struct dirent *)readdir(dir);
+ dir_ent != NULL; dir_ent = (struct dirent *)readdir(dir)) {
- /* Don't remove "." or ".." */
- if (!strcmp(dir_ent->d_name, ".") || !strcmp(dir_ent->d_name, ".."))
- continue;
+ /* Don't remove "." or ".." */
+ if (!strcmp(dir_ent->d_name, ".")
+ || !strcmp(dir_ent->d_name, ".."))
+ continue;
- /* Recursively call this routine to remove the current entry */
- sprintf(dirobj, "%s/%s", obj, dir_ent->d_name);
- if (rmobj(dirobj, errmsg) != 0)
- ret_val = -1;
- }
+ /* Recursively call this routine to remove the current entry */
+ sprintf(dirobj, "%s/%s", obj, dir_ent->d_name);
+ if (rmobj(dirobj, errmsg) != 0)
+ ret_val = -1;
+ }
- /* Close the directory */
- closedir(dir);
+ /* Close the directory */
+ closedir(dir);
- /* If there were problems removing an entry, don't attempt to
- remove the directory itself */
- if (ret_val == -1)
- return -1;
+ /* If there were problems removing an entry, don't attempt to
+ remove the directory itself */
+ if (ret_val == -1)
+ return -1;
- /* Get the link count, now that all the entries have been removed */
- if (lstat(obj, &statbuf) < 0) {
- if (errmsg != NULL) {
- sprintf(err_msg, "lstat(%s) failed; errno=%d: %s",
- obj, errno, SYSERR);
- *errmsg = err_msg;
- }
- return -1;
- }
+ /* Get the link count, now that all the entries have been removed */
+ if (lstat(obj, &statbuf) < 0) {
+ if (errmsg != NULL) {
+ sprintf(err_msg,
+ "lstat(%s) failed; errno=%d: %s", obj,
+ errno, SYSERR);
+ *errmsg = err_msg;
+ }
+ return -1;
+ }
- /* Remove the directory itself */
- if (statbuf.st_nlink >= 3) {
- /* The directory is linked; unlink() must be used */
- if (unlink(obj) < 0) {
- if (errmsg != NULL) {
- sprintf(err_msg, "unlink(%s) failed; errno=%d: %s",
- obj, errno, SYSERR);
- *errmsg = err_msg;
- }
- return -1;
- }
- } else {
- /* The directory is not linked; remove() can be used */
- if (remove(obj) < 0) {
- if (errmsg != NULL) {
- sprintf(err_msg, "remove(%s) failed; errno=%d: %s",
- obj, errno, SYSERR);
- *errmsg = err_msg;
- }
- return -1;
- }
- }
- } else {
- /* object is not a directory; just use unlink() */
- if (unlink(obj) < 0) {
- if (errmsg != NULL) {
- sprintf(err_msg, "unlink(%s) failed; errno=%d: %s",
- obj, errno, SYSERR);
- *errmsg = err_msg;
- }
- return -1;
- }
- } /* if obj is a directory */
+ /* Remove the directory itself */
+ if (statbuf.st_nlink >= 3) {
+ /* The directory is linked; unlink() must be used */
+ if (unlink(obj) < 0) {
+ if (errmsg != NULL) {
+ sprintf(err_msg,
+ "unlink(%s) failed; errno=%d: %s",
+ obj, errno, SYSERR);
+ *errmsg = err_msg;
+ }
+ return -1;
+ }
+ } else {
+ /* The directory is not linked; remove() can be used */
+ if (remove(obj) < 0) {
+ if (errmsg != NULL) {
+ sprintf(err_msg,
+ "remove(%s) failed; errno=%d: %s",
+ obj, errno, SYSERR);
+ *errmsg = err_msg;
+ }
+ return -1;
+ }
+ }
+ } else {
+ /* object is not a directory; just use unlink() */
+ if (unlink(obj) < 0) {
+ if (errmsg != NULL) {
+ sprintf(err_msg,
+ "unlink(%s) failed; errno=%d: %s", obj,
+ errno, SYSERR);
+ *errmsg = err_msg;
+ }
+ return -1;
+ }
+ } /* if obj is a directory */
- /*
- * Everything must have went ok.
- */
- return 0;
-} /* rmobj() */
+ /*
+ * Everything must have went ok.
+ */
+ return 0;
+} /* rmobj() */
diff --git a/lib/safe_file_ops.c b/lib/safe_file_ops.c
index b1b11f3..b602345 100644
--- a/lib/safe_file_ops.c
+++ b/lib/safe_file_ops.c
@@ -49,17 +49,17 @@
flag = 1;
cnt++;
}
- break;
+ break;
case '*':
if (flag) {
cnt--;
flag = 0;
}
- break;
+ break;
default:
flag = 0;
}
-
+
fmt++;
}
@@ -67,7 +67,7 @@
}
void safe_file_scanf(const char *file, const int lineno,
- void (*cleanup_fn)(void),
+ void (*cleanup_fn) (void),
const char *path, const char *fmt, ...)
{
va_list va;
@@ -78,34 +78,33 @@
if (f == NULL) {
tst_brkm(TBROK | TERRNO, cleanup_fn,
- "Failed to open FILE '%s' for reading at %s:%d",
- path, file, lineno);
+ "Failed to open FILE '%s' for reading at %s:%d",
+ path, file, lineno);
}
-
+
exp_convs = count_scanf_conversions(fmt);
va_start(va, fmt);
ret = vfscanf(f, fmt, va);
va_end(va);
-
+
if (ret == EOF) {
tst_brkm(TBROK, cleanup_fn,
- "The FILE '%s' ended prematurely at %s:%d",
- path, file, lineno);
+ "The FILE '%s' ended prematurely at %s:%d",
+ path, file, lineno);
}
if (ret != exp_convs) {
tst_brkm(TBROK, cleanup_fn,
- "Expected %i conversions got %i FILE '%s' at %s:%d",
- exp_convs, ret, path, file, lineno);
+ "Expected %i conversions got %i FILE '%s' at %s:%d",
+ exp_convs, ret, path, file, lineno);
}
}
-
void safe_file_printf(const char *file, const int lineno,
- void (*cleanup_fn)(void),
- const char *path, const char *fmt, ...)
+ void (*cleanup_fn) (void),
+ const char *path, const char *fmt, ...)
{
va_list va;
FILE *f;
@@ -114,31 +113,30 @@
if (f == NULL) {
tst_brkm(TBROK | TERRNO, cleanup_fn,
- "Failed to open FILE '%s' for writing at %s:%d",
- path, file, lineno);
+ "Failed to open FILE '%s' for writing at %s:%d",
+ path, file, lineno);
}
va_start(va, fmt);
if (vfprintf(f, fmt, va) < 0) {
tst_brkm(TBROK, cleanup_fn,
- "Failed to print to FILE '%s' at %s:%d",
- path, file, lineno);
+ "Failed to print to FILE '%s' at %s:%d",
+ path, file, lineno);
}
va_end(va);
if (fclose(f)) {
tst_brkm(TBROK | TERRNO, cleanup_fn,
- "Failed to close FILE '%s' at %s:%d",
- path, file, lineno);
+ "Failed to close FILE '%s' at %s:%d",
+ path, file, lineno);
}
}
//TODO: C implementation? better error condition reporting?
void safe_cp(const char *file, const int lineno,
- void (*cleanup_fn)(void),
- const char *src, const char *dst)
+ void (*cleanup_fn) (void), const char *src, const char *dst)
{
size_t len = strlen(src) + strlen(dst) + 16;
char buf[len];
@@ -150,7 +148,7 @@
if (ret) {
tst_brkm(TBROK, cleanup_fn,
- "Failed to copy '%s' to '%s' at %s:%d",
- src, dst, file, lineno);
+ "Failed to copy '%s' to '%s' at %s:%d",
+ src, dst, file, lineno);
}
}
diff --git a/lib/safe_macros.c b/lib/safe_macros.c
index 9c50f89..0668584 100644
--- a/lib/safe_macros.c
+++ b/lib/safe_macros.c
@@ -13,177 +13,172 @@
#include "test.h"
#include "safe_macros.h"
-char *
-safe_basename(const char *file, const int lineno, void (*cleanup_fn)(void),
- char *path)
+char *safe_basename(const char *file, const int lineno,
+ void (*cleanup_fn) (void), char *path)
{
char *rval;
rval = basename(path);
if (rval == NULL)
- tst_brkm(TBROK|TERRNO, cleanup_fn, "basename failed at %s:%d",
- file, lineno);
+ tst_brkm(TBROK | TERRNO, cleanup_fn, "basename failed at %s:%d",
+ file, lineno);
return (rval);
}
int
-safe_chdir(const char *file, const int lineno, void (*cleanup_fn)(void),
- const char *path)
+safe_chdir(const char *file, const int lineno, void (*cleanup_fn) (void),
+ const char *path)
{
int rval;
rval = chdir(path);
if (rval == -1)
- tst_brkm(TBROK|TERRNO, cleanup_fn, "chdir failed at %s:%d",
- file, lineno);
+ tst_brkm(TBROK | TERRNO, cleanup_fn, "chdir failed at %s:%d",
+ file, lineno);
return (rval);
}
int
-safe_close(const char *file, const int lineno, void (*cleanup_fn)(void),
- int fildes)
+safe_close(const char *file, const int lineno, void (*cleanup_fn) (void),
+ int fildes)
{
int rval;
rval = close(fildes);
if (rval == -1)
- tst_brkm(TBROK|TERRNO, cleanup_fn, "close failed at %s:%d",
- file, lineno);
+ tst_brkm(TBROK | TERRNO, cleanup_fn, "close failed at %s:%d",
+ file, lineno);
return (rval);
}
int
-safe_creat(const char *file, const int lineno, void (*cleanup_fn)(void),
- char *pathname, mode_t mode)
+safe_creat(const char *file, const int lineno, void (*cleanup_fn) (void),
+ char *pathname, mode_t mode)
{
int rval;
rval = creat(pathname, mode);
if (rval == -1)
- tst_brkm(TBROK|TERRNO, cleanup_fn, "pipe failed at %s:%d",
- file, lineno);
+ tst_brkm(TBROK | TERRNO, cleanup_fn, "pipe failed at %s:%d",
+ file, lineno);
return (rval);
}
-char *
-safe_dirname(const char *file, const int lineno, void (*cleanup_fn)(void),
- char *path)
+char *safe_dirname(const char *file, const int lineno,
+ void (*cleanup_fn) (void), char *path)
{
char *rval;
rval = dirname(path);
if (rval == NULL)
- tst_brkm(TBROK|TERRNO, cleanup_fn, "dirname failed at %s:%d",
- file, lineno);
+ tst_brkm(TBROK | TERRNO, cleanup_fn, "dirname failed at %s:%d",
+ file, lineno);
return (rval);
}
-char *
-safe_getcwd(const char *file, const int lineno, void (*cleanup_fn)(void),
- char *buf, size_t size)
+char *safe_getcwd(const char *file, const int lineno, void (*cleanup_fn) (void),
+ char *buf, size_t size)
{
char *rval;
rval = getcwd(buf, size);
if (rval == NULL)
- tst_brkm(TBROK|TERRNO, cleanup_fn, "getcwd failed at %s:%d",
- file, lineno);
+ tst_brkm(TBROK | TERRNO, cleanup_fn, "getcwd failed at %s:%d",
+ file, lineno);
return (rval);
}
-struct passwd*
-safe_getpwnam(const char *file, const int lineno, void (*cleanup_fn)(void),
- const char *name)
+struct passwd *safe_getpwnam(const char *file, const int lineno,
+ void (*cleanup_fn) (void), const char *name)
{
struct passwd *rval;
rval = getpwnam(name);
if (rval == NULL)
- tst_brkm(TBROK|TERRNO, cleanup_fn, "getpwnam failed at %s:%d",
- file, lineno);
+ tst_brkm(TBROK | TERRNO, cleanup_fn, "getpwnam failed at %s:%d",
+ file, lineno);
return (rval);
}
int
-safe_getrusage(const char *file, const int lineno, void (*cleanup_fn)(void),
- int who, struct rusage *usage)
+safe_getrusage(const char *file, const int lineno, void (*cleanup_fn) (void),
+ int who, struct rusage *usage)
{
int rval;
rval = getrusage(who, usage);
if (rval == -1)
- tst_brkm(TBROK|TERRNO, cleanup_fn, "getrusage failed at %s:%d",
- file, lineno);
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "getrusage failed at %s:%d", file, lineno);
return rval;
}
-void*
-safe_malloc(const char *file, const int lineno, void (*cleanup_fn)(void),
- size_t size)
+void *safe_malloc(const char *file, const int lineno, void (*cleanup_fn) (void),
+ size_t size)
{
void *rval;
rval = malloc(size);
if (rval == NULL)
- tst_brkm(TBROK|TERRNO, cleanup_fn, "malloc failed at %s:%d",
- file, lineno);
+ tst_brkm(TBROK | TERRNO, cleanup_fn, "malloc failed at %s:%d",
+ file, lineno);
return (rval);
}
int
-safe_mkdir(const char *file, const int lineno, void (*cleanup_fn)(void),
- const char *pathname, mode_t mode)
+safe_mkdir(const char *file, const int lineno, void (*cleanup_fn) (void),
+ const char *pathname, mode_t mode)
{
int rval;
rval = mkdir(pathname, mode);
if (rval == -1)
- tst_brkm(TBROK|TERRNO, cleanup_fn, "mkdir failed at %s:%d",
- file, lineno);
+ tst_brkm(TBROK | TERRNO, cleanup_fn, "mkdir failed at %s:%d",
+ file, lineno);
return (rval);
}
-void*
-safe_mmap(const char *file, const int lineno, void (*cleanup_fn)(void),
- void *addr, size_t length, int prot, int flags, int fd, off_t offset)
+void *safe_mmap(const char *file, const int lineno, void (*cleanup_fn) (void),
+ void *addr, size_t length, int prot, int flags, int fd,
+ off_t offset)
{
void *rval;
rval = mmap(addr, length, prot, flags, fd, offset);
if (rval == MAP_FAILED)
- tst_brkm(TBROK|TERRNO, cleanup_fn, "mmap failed at %s:%d",
- file, lineno);
+ tst_brkm(TBROK | TERRNO, cleanup_fn, "mmap failed at %s:%d",
+ file, lineno);
return (rval);
}
int
-safe_munmap(const char *file, const int lineno, void (*cleanup_fn)(void),
- void *addr, size_t length)
+safe_munmap(const char *file, const int lineno, void (*cleanup_fn) (void),
+ void *addr, size_t length)
{
int rval;
rval = munmap(addr, length);
if (rval == -1)
- tst_brkm(TBROK|TERRNO, cleanup_fn, "munmap failed at %s:%d",
- file, lineno);
+ tst_brkm(TBROK | TERRNO, cleanup_fn, "munmap failed at %s:%d",
+ file, lineno);
return (rval);
}
int
-safe_open(const char *file, const int lineno, void (*cleanup_fn)(void),
- const char *pathname, int oflags, ...)
+safe_open(const char *file, const int lineno, void (*cleanup_fn) (void),
+ const char *pathname, int oflags, ...)
{
va_list ap;
int rval;
@@ -195,154 +190,154 @@
rval = open(pathname, oflags, mode);
if (rval == -1)
- tst_brkm(TBROK|TERRNO, cleanup_fn, "open failed at %s:%d",
- file, lineno);
+ tst_brkm(TBROK | TERRNO, cleanup_fn, "open failed at %s:%d",
+ file, lineno);
return (rval);
}
int
-safe_pipe(const char *file, const int lineno, void (*cleanup_fn)(void),
- int fildes[2])
+safe_pipe(const char *file, const int lineno, void (*cleanup_fn) (void),
+ int fildes[2])
{
int rval;
rval = pipe(fildes);
if (rval == -1)
- tst_brkm(TBROK|TERRNO, cleanup_fn, "pipe failed at %s:%d",
- file, lineno);
+ tst_brkm(TBROK | TERRNO, cleanup_fn, "pipe failed at %s:%d",
+ file, lineno);
return (rval);
}
ssize_t
-safe_read(const char *file, const int lineno, void (*cleanup_fn)(void),
- char len_strict, int fildes, void *buf, size_t nbyte)
+safe_read(const char *file, const int lineno, void (*cleanup_fn) (void),
+ char len_strict, int fildes, void *buf, size_t nbyte)
{
ssize_t rval;
rval = read(fildes, buf, nbyte);
if (rval == -1 || (len_strict && rval != nbyte))
- tst_brkm(TBROK|TERRNO, cleanup_fn, "read failed at %s:%d",
- file, lineno);
+ tst_brkm(TBROK | TERRNO, cleanup_fn, "read failed at %s:%d",
+ file, lineno);
return (rval);
}
- int
-safe_setegid(const char *file, const int lineno, void (*cleanup_fn)(void),
- gid_t egid)
+int
+safe_setegid(const char *file, const int lineno, void (*cleanup_fn) (void),
+ gid_t egid)
{
int rval;
rval = setegid(egid);
if (rval == -1)
- tst_brkm(TBROK|TERRNO, cleanup_fn, "setegid failed at %s:%d",
- file, lineno);
+ tst_brkm(TBROK | TERRNO, cleanup_fn, "setegid failed at %s:%d",
+ file, lineno);
return (rval);
}
int
-safe_seteuid(const char *file, const int lineno, void (*cleanup_fn)(void),
- uid_t euid)
+safe_seteuid(const char *file, const int lineno, void (*cleanup_fn) (void),
+ uid_t euid)
{
int rval;
rval = seteuid(euid);
if (rval == -1)
- tst_brkm(TBROK|TERRNO, cleanup_fn, "seteuid failed at %s:%d",
- file, lineno);
+ tst_brkm(TBROK | TERRNO, cleanup_fn, "seteuid failed at %s:%d",
+ file, lineno);
return (rval);
}
int
-safe_setgid(const char *file, const int lineno, void (*cleanup_fn)(void),
- gid_t gid)
+safe_setgid(const char *file, const int lineno, void (*cleanup_fn) (void),
+ gid_t gid)
{
int rval;
rval = setgid(gid);
if (rval == -1)
- tst_brkm(TBROK|TERRNO, cleanup_fn, "setgid failed at %s:%d",
- file, lineno);
+ tst_brkm(TBROK | TERRNO, cleanup_fn, "setgid failed at %s:%d",
+ file, lineno);
return (rval);
}
int
-safe_setuid(const char *file, const int lineno, void (*cleanup_fn)(void),
- uid_t uid)
+safe_setuid(const char *file, const int lineno, void (*cleanup_fn) (void),
+ uid_t uid)
{
int rval;
rval = setuid(uid);
if (rval == -1)
- tst_brkm(TBROK|TERRNO, cleanup_fn, "setuid failed at %s:%d",
- file, lineno);
+ tst_brkm(TBROK | TERRNO, cleanup_fn, "setuid failed at %s:%d",
+ file, lineno);
return (rval);
}
int
-safe_unlink(const char *file, const int lineno, void (*cleanup_fn)(void),
- const char *pathname)
+safe_unlink(const char *file, const int lineno, void (*cleanup_fn) (void),
+ const char *pathname)
{
int rval;
rval = unlink(pathname);
if (rval == -1)
- tst_brkm(TBROK|TERRNO, cleanup_fn, "unlink failed at %s:%d",
- file, lineno);
+ tst_brkm(TBROK | TERRNO, cleanup_fn, "unlink failed at %s:%d",
+ file, lineno);
return (rval);
}
ssize_t
-safe_write(const char *file, const int lineno, void (cleanup_fn)(void),
- char len_strict, int fildes, const void *buf, size_t nbyte)
+safe_write(const char *file, const int lineno, void (cleanup_fn) (void),
+ char len_strict, int fildes, const void *buf, size_t nbyte)
{
ssize_t rval;
rval = write(fildes, buf, nbyte);
if ((len_strict == 0 && rval == -1) || rval != nbyte)
- tst_brkm(TBROK|TERRNO, cleanup_fn, "write failed at %s:%d",
- file, lineno);
+ tst_brkm(TBROK | TERRNO, cleanup_fn, "write failed at %s:%d",
+ file, lineno);
return (rval);
}
int safe_ftruncate(const char *file, const int lineno,
- void (cleanup_fn)(void), int fd, off_t length)
+ void (cleanup_fn) (void), int fd, off_t length)
{
int rval;
rval = ftruncate(fd, length);
if (rval == -1) {
- tst_brkm(TBROK|TERRNO, cleanup_fn, "ftruncate failed at %s:%d",
- file, lineno);
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "ftruncate failed at %s:%d", file, lineno);
}
return rval;
}
int safe_truncate(const char *file, const int lineno,
- void (cleanup_fn)(void), const char *path, off_t length)
+ void (cleanup_fn) (void), const char *path, off_t length)
{
int rval;
rval = truncate(path, length);
if (rval == -1) {
- tst_brkm(TBROK|TERRNO, cleanup_fn, "truncate failed at %s:%d",
- file, lineno);
+ tst_brkm(TBROK | TERRNO, cleanup_fn, "truncate failed at %s:%d",
+ file, lineno);
}
return rval;
}
long safe_strtol(const char *file, const int lineno,
- void (cleanup_fn)(void), char *str, long min, long max)
+ void (cleanup_fn) (void), char *str, long min, long max)
{
long rval;
char *endptr;
@@ -350,8 +345,8 @@
errno = 0;
rval = strtol(str, &endptr, 10);
if ((errno == ERANGE && (rval == LONG_MAX || rval == LONG_MIN))
- || (errno != 0 && rval == 0))
- tst_brkm(TBROK|TERRNO, cleanup_fn,
+ || (errno != 0 && rval == 0))
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
"strtol failed at %s:%d", file, lineno);
if (rval > max || rval < min)
tst_brkm(TBROK, cleanup_fn,
@@ -364,8 +359,9 @@
return rval;
}
-unsigned long safe_strtoul(const char *file, const int lineno, void (cleanup_fn)(void),
- char *str, unsigned long min, unsigned long max)
+unsigned long safe_strtoul(const char *file, const int lineno,
+ void (cleanup_fn) (void), char *str,
+ unsigned long min, unsigned long max)
{
unsigned long rval;
char *endptr;
@@ -373,22 +369,22 @@
errno = 0;
rval = strtoul(str, &endptr, 10);
if ((errno == ERANGE && rval == ULONG_MAX)
- || (errno != 0 && rval == 0))
- tst_brkm(TBROK|TERRNO, cleanup_fn,
- "strtol failed at %s:%d", file, lineno);
+ || (errno != 0 && rval == 0))
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "strtol failed at %s:%d", file, lineno);
if (rval > max || rval < min)
tst_brkm(TBROK, cleanup_fn,
- "converted value out of range (%lu - %lu at %s:%d",
- min, max, file, lineno);
+ "converted value out of range (%lu - %lu at %s:%d",
+ min, max, file, lineno);
if (endptr == str || (*endptr != '\0' && *endptr != '\n'))
tst_brkm(TBROK, cleanup_fn,
- "Invalid value: '%s' at %s:%d", str, file, lineno);
+ "Invalid value: '%s' at %s:%d", str, file, lineno);
return rval;
}
long safe_sysconf(const char *file, const int lineno,
- void (cleanup_fn)(void), int name)
+ void (cleanup_fn) (void), int name)
{
long rval;
errno = 0;
@@ -397,7 +393,7 @@
if (rval == -1) {
if (errno == EINVAL)
- tst_brkm(TBROK|TERRNO, cleanup_fn,
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
"sysconf failed at %s:%d", file, lineno);
else
tst_resm(TINFO, "queried option is not available"
diff --git a/lib/search_path.c b/lib/search_path.c
index 28b4ca7..a5ebfad 100644
--- a/lib/search_path.c
+++ b/lib/search_path.c
@@ -32,7 +32,6 @@
* http://oss.sgi.com/projects/GenInfo/NoticeExplan/
*/
-
/**********************************************************
*
* UNICOS Feature Test and Evaluation - Cray Research, Inc.
@@ -80,7 +79,6 @@
#include <sys/param.h>
#include <sys/stat.h>
-
struct stat stbuf;
#ifndef AS_CMD
@@ -94,33 +92,31 @@
#ifndef PATH_MAX
#ifndef MAXPATHLEN
#define PATH_MAX 1024
-#else /* MAXPATHLEN */
+#else /* MAXPATHLEN */
#define PATH_MAX MAXPATHLEN
-#endif /* MAXPATHLEN */
-#endif /* PATH_MAX */
-
+#endif /* MAXPATHLEN */
+#endif /* PATH_MAX */
#if AS_CMD
main(argc, argv)
int argc;
char **argv;
{
- char path[PATH_MAX];
- int ind;
+ char path[PATH_MAX];
+ int ind;
- if (argc <= 1) {
- printf("missing argument\n");
- exit(1);
- }
+ if (argc <= 1) {
+ printf("missing argument\n");
+ exit(1);
+ }
- for (ind=1;ind < argc; ind++) {
- if (search_path(argv[ind], path, F_OK, 0) < 0) {
- printf("ERROR: %s\n", path);
+ for (ind = 1; ind < argc; ind++) {
+ if (search_path(argv[ind], path, F_OK, 0) < 0) {
+ printf("ERROR: %s\n", path);
+ } else {
+ printf("path of %s is %s\n", argv[ind], path);
+ }
}
- else {
- printf("path of %s is %s\n", argv[ind], path);
- }
- }
}
@@ -128,150 +124,150 @@
/*
*/
-int
-search_path(cmd, res_path, access_mode, fullpath)
-char *cmd; /* The requested filename */
-char *res_path; /* The resulting path or error mesg */
-int access_mode; /* the mode used by access(2) */
-int fullpath; /* if set, cwd will be prepended to all non-full paths */
+int search_path(cmd, res_path, access_mode, fullpath)
+char *cmd; /* The requested filename */
+char *res_path; /* The resulting path or error mesg */
+int access_mode; /* the mode used by access(2) */
+int fullpath; /* if set, cwd will be prepended to all non-full paths */
{
- char *cp; /* used to scan PATH for directories */
- int ret; /* return value from access */
- char *pathenv;
- char tmppath[PATH_MAX];
- char curpath[PATH_MAX];
- char *path;
- int lastpath;
- int toolong=0;
+ char *cp; /* used to scan PATH for directories */
+ int ret; /* return value from access */
+ char *pathenv;
+ char tmppath[PATH_MAX];
+ char curpath[PATH_MAX];
+ char *path;
+ int lastpath;
+ int toolong = 0;
#if DEBUG
-printf("search_path: cmd = %s, access_mode = %d, fullpath = %d\n", cmd, access_mode, fullpath);
+ printf("search_path: cmd = %s, access_mode = %d, fullpath = %d\n", cmd,
+ access_mode, fullpath);
#endif
- /*
- * full or relative path was given
- */
- if ((cmd[0] == '/') || ( (cp=strchr(cmd, '/')) != NULL )) {
- if (access(cmd, access_mode) == 0) {
-
- if (cmd[0] != '/') { /* relative path */
- if (getcwd(curpath, PATH_MAX) == NULL) {
- strcpy(res_path, curpath);
- return -1;
- }
- if ((strlen(curpath) + strlen(cmd) + 1) > (size_t)PATH_MAX) {
- sprintf(res_path, "cmd (as relative path) and cwd is longer than %d",
- PATH_MAX);
- return -1;
- }
- sprintf(res_path, "%s/%s", curpath, cmd);
- }
- else
- strcpy(res_path, cmd);
- return 0;
- }
- else {
- sprintf(res_path, "file %s not found", cmd);
- return -1;
- }
- }
-
- /* get the PATH variable */
- if ((pathenv=getenv("PATH")) == NULL) {
- /* no path to scan, return */
- sprintf(res_path, "Unable to get PATH env. variable");
- return -1;
- }
-
- /*
- * walk through each path in PATH.
- * Each path in PATH is placed in tmppath.
- * pathenv cannot be modified since it will affect PATH.
- * If a signal came in while we have modified the PATH
- * memory, we could create a problem for the caller.
- */
-
- curpath[0]='\0';
-
- cp = pathenv;
- path = pathenv;
- lastpath = 0;
- for (;;) {
-
- if (lastpath)
- break;
-
- if (cp != pathenv)
- path = ++cp; /* already set on first iteration */
-
- /* find end of current path */
-
- for (; ((*cp != ':') && (*cp != '\0')); cp++);
-
/*
- * copy path to tmppath so it can be NULL terminated
- * and so we do not modify path memory.
+ * full or relative path was given
*/
- strncpy(tmppath, path, (cp-path) );
- tmppath[cp-path]='\0';
-#if DEBUG
-printf("search_path: tmppath = %s\n", tmppath);
-#endif
+ if ((cmd[0] == '/') || ((cp = strchr(cmd, '/')) != NULL)) {
+ if (access(cmd, access_mode) == 0) {
- if (*cp == '\0')
- lastpath=1; /* this is the last path entry */
-
- /* Check lengths so not to overflow res_path */
- if (strlen(tmppath) + strlen(cmd) + 2 > (size_t)PATH_MAX) {
- toolong++;
- continue;
+ if (cmd[0] != '/') { /* relative path */
+ if (getcwd(curpath, PATH_MAX) == NULL) {
+ strcpy(res_path, curpath);
+ return -1;
+ }
+ if ((strlen(curpath) + strlen(cmd) + 1) >
+ (size_t) PATH_MAX) {
+ sprintf(res_path,
+ "cmd (as relative path) and cwd is longer than %d",
+ PATH_MAX);
+ return -1;
+ }
+ sprintf(res_path, "%s/%s", curpath, cmd);
+ } else
+ strcpy(res_path, cmd);
+ return 0;
+ } else {
+ sprintf(res_path, "file %s not found", cmd);
+ return -1;
+ }
}
- sprintf(res_path, "%s/%s", tmppath, cmd);
-#if DEBUG
-printf("search_path: res_path = '%s'\n", res_path);
-#endif
-
-
- /* if the path is not full at this point, prepend the current
- * path to get the full path.
- * Note: this could not be wise to do when under a protected
- * directory.
- */
-
- if (fullpath && res_path[0] != '/') { /* not a full path */
- if (curpath[0] == '\0') {
- if (getcwd(curpath, PATH_MAX) == NULL) {
- strcpy(res_path, curpath);
- return -1;
- }
- }
- if ((strlen(curpath) + strlen(res_path) + 2) > (size_t)PATH_MAX) {
- toolong++;
- continue;
- }
- sprintf(tmppath, "%s/%s", curpath, res_path);
- strcpy(res_path, tmppath);
-#if DEBUG
-printf("search_path: full res_path= '%s'\n", res_path);
-#endif
-
+ /* get the PATH variable */
+ if ((pathenv = getenv("PATH")) == NULL) {
+ /* no path to scan, return */
+ sprintf(res_path, "Unable to get PATH env. variable");
+ return -1;
}
+ /*
+ * walk through each path in PATH.
+ * Each path in PATH is placed in tmppath.
+ * pathenv cannot be modified since it will affect PATH.
+ * If a signal came in while we have modified the PATH
+ * memory, we could create a problem for the caller.
+ */
- if ((ret=access(res_path, access_mode)) == 0) {
+ curpath[0] = '\0';
+
+ cp = pathenv;
+ path = pathenv;
+ lastpath = 0;
+ for (;;) {
+
+ if (lastpath)
+ break;
+
+ if (cp != pathenv)
+ path = ++cp; /* already set on first iteration */
+
+ /* find end of current path */
+
+ for (; ((*cp != ':') && (*cp != '\0')); cp++) ;
+
+ /*
+ * copy path to tmppath so it can be NULL terminated
+ * and so we do not modify path memory.
+ */
+ strncpy(tmppath, path, (cp - path));
+ tmppath[cp - path] = '\0';
#if DEBUG
-printf("search_path: found res_path = %s\n", res_path);
+ printf("search_path: tmppath = %s\n", tmppath);
#endif
- return 0;
- }
- }
- /* return failure */
- if (toolong)
- sprintf(res_path,
- "Unable to find file, %d path/file strings were too long", toolong);
- else
- strcpy(res_path, "Unable to find file");
- return 1; /* not found */
+ if (*cp == '\0')
+ lastpath = 1; /* this is the last path entry */
+
+ /* Check lengths so not to overflow res_path */
+ if (strlen(tmppath) + strlen(cmd) + 2 > (size_t) PATH_MAX) {
+ toolong++;
+ continue;
+ }
+
+ sprintf(res_path, "%s/%s", tmppath, cmd);
+#if DEBUG
+ printf("search_path: res_path = '%s'\n", res_path);
+#endif
+
+ /* if the path is not full at this point, prepend the current
+ * path to get the full path.
+ * Note: this could not be wise to do when under a protected
+ * directory.
+ */
+
+ if (fullpath && res_path[0] != '/') { /* not a full path */
+ if (curpath[0] == '\0') {
+ if (getcwd(curpath, PATH_MAX) == NULL) {
+ strcpy(res_path, curpath);
+ return -1;
+ }
+ }
+ if ((strlen(curpath) + strlen(res_path) + 2) >
+ (size_t) PATH_MAX) {
+ toolong++;
+ continue;
+ }
+ sprintf(tmppath, "%s/%s", curpath, res_path);
+ strcpy(res_path, tmppath);
+#if DEBUG
+ printf("search_path: full res_path= '%s'\n", res_path);
+#endif
+
+ }
+
+ if ((ret = access(res_path, access_mode)) == 0) {
+#if DEBUG
+ printf("search_path: found res_path = %s\n", res_path);
+#endif
+ return 0;
+ }
+ }
+
+ /* return failure */
+ if (toolong)
+ sprintf(res_path,
+ "Unable to find file, %d path/file strings were too long",
+ toolong);
+ else
+ strcpy(res_path, "Unable to find file");
+ return 1; /* not found */
}
diff --git a/lib/self_exec.c b/lib/self_exec.c
index 31ccdaa..06af313 100644
--- a/lib/self_exec.c
+++ b/lib/self_exec.c
@@ -22,7 +22,7 @@
* 55 Byward Market Square, 2nd Floor North, Ottawa, ON K1N 9C3, Canada
*/
-#define _GNU_SOURCE /* for asprintf */
+#define _GNU_SOURCE /* for asprintf */
#include "config.h"
@@ -34,176 +34,187 @@
#include "test.h"
/* Set from parse_opts.c: */
-char *child_args; /* Arguments to child when -C is used */
+char *child_args; /* Arguments to child when -C is used */
-static char *start_cwd; /* Stores the starting directory for self_exec */
+static char *start_cwd; /* Stores the starting directory for self_exec */
int asprintf(char **app, const char *fmt, ...)
{
- va_list ptr;
- int rv;
- char *p;
+ va_list ptr;
+ int rv;
+ char *p;
- /*
- * First iteration - find out size of buffer required and allocate it.
- */
- va_start(ptr, fmt);
- rv = vsnprintf(NULL, 0, fmt, ptr);
- va_end(ptr);
+ /*
+ * First iteration - find out size of buffer required and allocate it.
+ */
+ va_start(ptr, fmt);
+ rv = vsnprintf(NULL, 0, fmt, ptr);
+ va_end(ptr);
- p = malloc(++rv); /* allocate the buffer */
- *app = p;
- if (!p) {
- return -1;
- }
+ p = malloc(++rv); /* allocate the buffer */
+ *app = p;
+ if (!p) {
+ return -1;
+ }
- /*
- * Second iteration - actually produce output.
- */
- va_start(ptr, fmt);
- rv = vsnprintf(p, rv, fmt, ptr);
- va_end(ptr);
+ /*
+ * Second iteration - actually produce output.
+ */
+ va_start(ptr, fmt);
+ rv = vsnprintf(p, rv, fmt, ptr);
+ va_end(ptr);
- return rv;
+ return rv;
}
-void
-maybe_run_child(void (*child)(), char *fmt, ...)
+void maybe_run_child(void (*child) (), char *fmt, ...)
{
- va_list ap;
- char *child_dir;
- char *p, *tok;
- int *iptr, i, j;
- char *s;
- char **sptr;
- char *endptr;
+ va_list ap;
+ char *child_dir;
+ char *p, *tok;
+ int *iptr, i, j;
+ char *s;
+ char **sptr;
+ char *endptr;
- /* Store the current directory for later use. */
- start_cwd = getcwd(NULL, 0);
+ /* Store the current directory for later use. */
+ start_cwd = getcwd(NULL, 0);
- if (child_args) {
- char *args = strdup(child_args);
+ if (child_args) {
+ char *args = strdup(child_args);
- child_dir = strtok(args, ",");
- if (strlen(child_dir) == 0) {
- tst_brkm(TBROK, NULL, "Could not get directory from -C option");
+ child_dir = strtok(args, ",");
+ if (strlen(child_dir) == 0) {
+ tst_brkm(TBROK, NULL,
+ "Could not get directory from -C option");
+ }
+
+ va_start(ap, fmt);
+
+ for (p = fmt; *p; p++) {
+ tok = strtok(NULL, ",");
+ if (!tok || strlen(tok) == 0) {
+ tst_brkm(TBROK, NULL,
+ "Invalid argument to -C option");
+ }
+
+ switch (*p) {
+ case 'd':
+ iptr = va_arg(ap, int *);
+ i = strtol(tok, &endptr, 10);
+ if (*endptr != '\0') {
+ tst_brkm(TBROK, NULL,
+ "Invalid argument to -C option");
+ }
+ *iptr = i;
+ break;
+ case 'n':
+ j = va_arg(ap, int);
+ i = strtol(tok, &endptr, 10);
+ if (*endptr != '\0') {
+ tst_brkm(TBROK, NULL,
+ "Invalid argument to -C option");
+ }
+ if (j != i) {
+ va_end(ap);
+ return;
+ }
+ break;
+ case 's':
+ s = va_arg(ap, char *);
+ if (!strncpy(s, tok, strlen(tok) + 1)) {
+ tst_brkm(TBROK, NULL,
+ "Could not strncpy for -C option");
+ }
+ break;
+ case 'S':
+ sptr = va_arg(ap, char **);
+ *sptr = strdup(tok);
+ if (!*sptr) {
+ tst_brkm(TBROK, NULL,
+ "Could not strdup for -C option");
+ }
+ break;
+ default:
+ tst_brkm(TBROK, NULL,
+ "Format string option %c not implemented",
+ *p);
+ break;
+ }
+ }
+
+ va_end(ap);
+
+ if (chdir(child_dir) < 0)
+ tst_brkm(TBROK, NULL,
+ "Could not change to %s for child", child_dir);
+
+ (*child) ();
+ tst_resm(TWARN, "Child function returned unexpectedly");
+ /* Exit here? or exit silently? */
+ }
+}
+
+int self_exec(char *argv0, char *fmt, ...)
+{
+ va_list ap;
+ char *p;
+ char *tmp_cwd;
+ char *arg;
+ int ival;
+ char *str;
+
+ if ((tmp_cwd = getcwd(NULL, 0)) == NULL) {
+ tst_resm(TBROK, "Could not getcwd()");
+ return -1;
+ }
+
+ arg = strdup(tmp_cwd);
+
+ if ((arg = strdup(tmp_cwd)) == NULL) {
+ tst_resm(TBROK, "Could not produce self_exec string");
+ return -1;
}
va_start(ap, fmt);
for (p = fmt; *p; p++) {
- tok = strtok(NULL, ",");
- if (!tok || strlen(tok) == 0) {
- tst_brkm(TBROK, NULL, "Invalid argument to -C option");
- }
-
- switch (*p) {
- case 'd':
- iptr = va_arg(ap, int *);
- i = strtol(tok, &endptr, 10);
- if (*endptr != '\0') {
- tst_brkm(TBROK, NULL, "Invalid argument to -C option");
+ switch (*p) {
+ case 'd':
+ case 'n':
+ ival = va_arg(ap, int);
+ if (asprintf(&arg, "%s,%d", arg, ival) < 0) {
+ tst_resm(TBROK,
+ "Could not produce self_exec string");
+ return -1;
+ }
+ break;
+ case 's':
+ case 'S':
+ str = va_arg(ap, char *);
+ if (asprintf(&arg, "%s,%s", arg, str) < 0) {
+ tst_resm(TBROK,
+ "Could not produce self_exec string");
+ return -1;
+ }
+ break;
+ default:
+ tst_resm(TBROK,
+ "Format string option %c not implemented", *p);
+ return -1;
+ break;
}
- *iptr = i;
- break;
- case 'n':
- j = va_arg(ap, int);
- i = strtol(tok, &endptr, 10);
- if (*endptr != '\0') {
- tst_brkm(TBROK, NULL, "Invalid argument to -C option");
- }
- if (j != i) {
- va_end(ap);
- return;
- }
- break;
- case 's':
- s = va_arg(ap, char *);
- if (!strncpy(s, tok, strlen(tok)+1)) {
- tst_brkm(TBROK, NULL, "Could not strncpy for -C option");
- }
- break;
- case 'S':
- sptr = va_arg(ap, char **);
- *sptr = strdup(tok);
- if (!*sptr) {
- tst_brkm(TBROK, NULL, "Could not strdup for -C option");
- }
- break;
- default:
- tst_brkm(TBROK, NULL, "Format string option %c not implemented", *p);
- break;
- }
}
va_end(ap);
- if (chdir(child_dir) < 0)
- tst_brkm(TBROK, NULL, "Could not change to %s for child", child_dir);
-
- (*child)();
- tst_resm(TWARN, "Child function returned unexpectedly");
- /* Exit here? or exit silently? */
- }
-}
-
-int
-self_exec(char *argv0, char *fmt, ...)
-{
- va_list ap;
- char *p;
- char *tmp_cwd;
- char *arg;
- int ival;
- char *str;
-
- if ((tmp_cwd = getcwd(NULL, 0)) == NULL) {
- tst_resm(TBROK, "Could not getcwd()");
- return -1;
- }
-
- arg = strdup( tmp_cwd );
-
- if (( arg = strdup( tmp_cwd )) == NULL) {
- tst_resm(TBROK, "Could not produce self_exec string");
- return -1;
- }
-
- va_start(ap, fmt);
-
- for (p = fmt; *p; p++) {
- switch (*p) {
- case 'd':
- case 'n':
- ival = va_arg(ap, int);
- if (asprintf(&arg, "%s,%d", arg, ival) < 0) {
- tst_resm(TBROK, "Could not produce self_exec string");
+ if (chdir(start_cwd) < 0) {
+ tst_resm(TBROK, "Could not change to %s for self_exec",
+ start_cwd);
return -1;
- }
- break;
- case 's':
- case 'S':
- str = va_arg(ap, char *);
- if (asprintf(&arg, "%s,%s", arg, str) < 0) {
- tst_resm(TBROK, "Could not produce self_exec string");
- return -1;
- }
- break;
- default:
- tst_resm(TBROK, "Format string option %c not implemented", *p);
- return -1;
- break;
}
- }
- va_end(ap);
-
- if (chdir(start_cwd) < 0) {
- tst_resm(TBROK, "Could not change to %s for self_exec", start_cwd);
- return -1;
- }
-
- return execlp(argv0, argv0, "-C", arg, (char *) NULL);
+ return execlp(argv0, argv0, "-C", arg, (char *)NULL);
}
#endif /* UCLINUX */
diff --git a/lib/string_to_tokens.c b/lib/string_to_tokens.c
index d1172ba..f313ee6 100644
--- a/lib/string_to_tokens.c
+++ b/lib/string_to_tokens.c
@@ -73,37 +73,38 @@
*
*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
#include <stdio.h>
-#include <string.h> /* for string functions */
+#include <string.h> /* for string functions */
#include "string_to_tokens.h"
int
-string_to_tokens(char *arg_string, char *arg_array[], int array_size, char *separator)
+string_to_tokens(char *arg_string, char *arg_array[], int array_size,
+ char *separator)
{
- int num_toks = 0; /* number of tokens found */
- char *strtok();
+ int num_toks = 0; /* number of tokens found */
+ char *strtok();
- if (arg_array == NULL || array_size <= 1 || separator == NULL)
- return -1;
+ if (arg_array == NULL || array_size <= 1 || separator == NULL)
+ return -1;
- /*
- * Use strtok() to parse 'arg_string', placing pointers to the
- * individual tokens into the elements of 'arg_array'.
- */
- if ((arg_array[num_toks] = strtok(arg_string, separator)) == NULL) {
- return 0;
- }
+ /*
+ * Use strtok() to parse 'arg_string', placing pointers to the
+ * individual tokens into the elements of 'arg_array'.
+ */
+ if ((arg_array[num_toks] = strtok(arg_string, separator)) == NULL) {
+ return 0;
+ }
- for (num_toks=1;num_toks<array_size; num_toks++) {
- if ((arg_array[num_toks] = strtok(NULL, separator)) == NULL)
- break;
- }
+ for (num_toks = 1; num_toks < array_size; num_toks++) {
+ if ((arg_array[num_toks] = strtok(NULL, separator)) == NULL)
+ break;
+ }
- if (num_toks == array_size)
- arg_array[num_toks] = NULL;
+ if (num_toks == array_size)
+ arg_array[num_toks] = NULL;
- /*
- * Return the number of tokens that were found in 'arg_string'.
- */
- return(num_toks);
+ /*
+ * Return the number of tokens that were found in 'arg_string'.
+ */
+ return (num_toks);
-} /* end of string_to_tokens */
+} /* end of string_to_tokens */
diff --git a/lib/system_specific_process_info.c b/lib/system_specific_process_info.c
index e960dfe..bc47d49 100644
--- a/lib/system_specific_process_info.c
+++ b/lib/system_specific_process_info.c
@@ -26,7 +26,6 @@
* of pids currently used ('ps -eT') from max_pids
*/
-
#include <fcntl.h>
#include <limits.h>
#include <sys/types.h>
@@ -58,7 +57,6 @@
#endif
}
-
int get_free_pids(void)
{
FILE *f;
@@ -66,8 +64,7 @@
f = popen("ps -eT | wc -l", "r");
if (!f) {
- tst_resm(TBROK, "Could not run 'ps' to calculate used "
- "pids");
+ tst_resm(TBROK, "Could not run 'ps' to calculate used " "pids");
return -1;
}
rc = fscanf(f, "%i", &used_pids);
@@ -75,7 +72,7 @@
if (rc != 1 || used_pids < 0) {
tst_resm(TBROK, "Could not read output of 'ps' to "
- "calculate used pids");
+ "calculate used pids");
return -1;
}
diff --git a/lib/tests/bytes_by_prefix_test.c b/lib/tests/bytes_by_prefix_test.c
index d2dc6a7..4e65bbd 100644
--- a/lib/tests/bytes_by_prefix_test.c
+++ b/lib/tests/bytes_by_prefix_test.c
@@ -159,7 +159,6 @@
{"552558G", 4746437078286336LL}
};
-
static int test_values(void)
{
/*
@@ -168,12 +167,12 @@
* 3rd position of the array denotes the valid long long operations
*/
int valid_count[3];
- int tests_number[3]; /* int / long / long long */
+ int tests_number[3]; /* int / long / long long */
int i;
int error_count = 0;
- int elements; /* Number of elements inside the test array. */
+ int elements; /* Number of elements inside the test array. */
- elements = sizeof(test)/sizeof(struct test_vals);
+ elements = sizeof(test) / sizeof(struct test_vals);
/*
* Initializing counters.
*/
@@ -205,12 +204,12 @@
valid_count[2]++;
} else {
printf("Test value:%s failed on long long.\n",
- test[i].val);
+ test[i].val);
error_count++;
}
}
- elements = sizeof(test_i)/sizeof(struct test_vals);
+ elements = sizeof(test_i) / sizeof(struct test_vals);
tests_number[0] += elements;
/*
@@ -220,13 +219,12 @@
if (bytes_by_prefix(test_i[i].val) == test_i[i].res) {
valid_count[0]++;
} else {
- printf("Test value:%s failed on int.\n",
- test_i[i].val);
+ printf("Test value:%s failed on int.\n", test_i[i].val);
error_count++;
}
}
- elements = sizeof(test_l)/sizeof(struct test_vals);
+ elements = sizeof(test_l) / sizeof(struct test_vals);
tests_number[1] += elements;
/*
@@ -237,12 +235,12 @@
valid_count[1]++;
} else {
printf("Test value:%s failed on long.\n",
- test_l[i].val);
+ test_l[i].val);
error_count++;
}
}
- elements = sizeof(test_ll)/sizeof(struct test_vals);
+ elements = sizeof(test_ll) / sizeof(struct test_vals);
tests_number[2] += elements;
/*
@@ -253,7 +251,7 @@
valid_count[2]++;
} else {
printf("Test value:%s failed on long long.\n",
- test_ll[i].val);
+ test_ll[i].val);
error_count++;
}
}
diff --git a/lib/tests/tst_tmpdir_test.c b/lib/tests/tst_tmpdir_test.c
index f4e6751..8b0065d 100644
--- a/lib/tests/tst_tmpdir_test.c
+++ b/lib/tests/tst_tmpdir_test.c
@@ -59,7 +59,7 @@
changed_dir = getcwd(NULL, PATH_MAX);
if (strcmp(tmp_dir, changed_dir) == 0 &&
- strcmp(tmp_dir, start_dir) != 0) {
+ strcmp(tmp_dir, start_dir) != 0) {
printf("Temp directory successfully created and switched to\n");
} else {
printf("Temp directory is wrong!\n");
diff --git a/lib/tlibio.c b/lib/tlibio.c
index 6a62bb7..9104a72 100644
--- a/lib/tlibio.c
+++ b/lib/tlibio.c
@@ -104,15 +104,15 @@
#include <sys/listio.h>
#else
/* for linux or sgi */
-#include <sys/uio.h> /* readv(2)/writev(2) */
-#include <string.h> /* bzero */
+#include <sys/uio.h> /* readv(2)/writev(2) */
+#include <string.h> /* bzero */
#endif
#if defined(__linux__) || defined(__sun) || defined(__hpux) || defined(_AIX)
#if !defined(UCLINUX) && !defined(__UCLIBC__)
#include <aio.h>
#endif
#endif
-#include <stdlib.h> /* atoi, abs */
+#include <stdlib.h> /* atoi, abs */
#include "tlibio.h" /* defines LIO* marcos */
#include "random_range.h"
@@ -121,15 +121,14 @@
#define PATH_MAX MAXPATHLEN
#endif
-#if 0 /* disabled until it's needed -- roehrich 6/11/97 */
-#define BUG1_workaround 1 /* Work around a condition where aio_return gives
- * a value of zero but there is no errno followup
- * and the read/write operation actually did its
- * job. spr/pv 705244
- */
+#if 0 /* disabled until it's needed -- roehrich 6/11/97 */
+#define BUG1_workaround 1 /* Work around a condition where aio_return gives
+ * a value of zero but there is no errno followup
+ * and the read/write operation actually did its
+ * job. spr/pv 705244
+ */
#endif
-
static void lio_async_signal_handler();
#ifdef sgi
static void lio_async_callback_handler();
@@ -138,49 +137,58 @@
/*
* Define the structure as used in lio_parse_arg1 and lio_help1
*/
-struct lio_info_type Lio_info1[] = {
- { "s", LIO_IO_SYNC, "sync i/o" },
- { "p", LIO_IO_ASYNC|LIO_WAIT_SIGACTIVE, "async i/o using a loop to wait for a signal" },
- { "b", LIO_IO_ASYNC|LIO_WAIT_SIGPAUSE, "async i/o using pause" },
- { "a", LIO_IO_ASYNC|LIO_WAIT_RECALL, "async i/o using recall/aio_suspend" },
+struct lio_info_type Lio_info1[] = {
+ {"s", LIO_IO_SYNC, "sync i/o"},
+ {"p", LIO_IO_ASYNC | LIO_WAIT_SIGACTIVE,
+ "async i/o using a loop to wait for a signal"},
+ {"b", LIO_IO_ASYNC | LIO_WAIT_SIGPAUSE, "async i/o using pause"},
+ {"a", LIO_IO_ASYNC | LIO_WAIT_RECALL,
+ "async i/o using recall/aio_suspend"},
#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
- { "r",
- LIO_RANDOM|LIO_IO_TYPES|LIO_WAIT_TYPES, "random sync i/o types and wait methods" },
- { "R",
- LIO_RANDOM|LIO_IO_ATYPES|LIO_WAIT_ATYPES, "random i/o types and wait methods" },
+ {"r",
+ LIO_RANDOM | LIO_IO_TYPES | LIO_WAIT_TYPES,
+ "random sync i/o types and wait methods"},
+ {"R",
+ LIO_RANDOM | LIO_IO_ATYPES | LIO_WAIT_ATYPES,
+ "random i/o types and wait methods"},
#else
- { "r",
- LIO_RANDOM|LIO_IO_TYPES|LIO_WAIT_TYPES, "random i/o types and wait methods" },
- { "R",
- LIO_RANDOM|LIO_IO_TYPES|LIO_WAIT_TYPES, "random i/o types and wait methods" },
+ {"r",
+ LIO_RANDOM | LIO_IO_TYPES | LIO_WAIT_TYPES,
+ "random i/o types and wait methods"},
+ {"R",
+ LIO_RANDOM | LIO_IO_TYPES | LIO_WAIT_TYPES,
+ "random i/o types and wait methods"},
#endif
- { "l", LIO_IO_SLISTIO|LIO_WAIT_RECALL, "single stride sync listio" },
- { "L", LIO_IO_ALISTIO|LIO_WAIT_RECALL, "single stride async listio using recall" },
- { "X", LIO_IO_ALISTIO|LIO_WAIT_SIGPAUSE, "single stride async listio using pause" },
- { "v", LIO_IO_SYNCV, "single buffer sync readv/writev" },
- { "P", LIO_IO_SYNCP, "sync pread/pwrite" },
+ {"l", LIO_IO_SLISTIO | LIO_WAIT_RECALL, "single stride sync listio"},
+ {"L", LIO_IO_ALISTIO | LIO_WAIT_RECALL,
+ "single stride async listio using recall"},
+ {"X", LIO_IO_ALISTIO | LIO_WAIT_SIGPAUSE,
+ "single stride async listio using pause"},
+ {"v", LIO_IO_SYNCV, "single buffer sync readv/writev"},
+ {"P", LIO_IO_SYNCP, "sync pread/pwrite"},
};
/*
* Define the structure used by lio_parse_arg2 and lio_help2
*/
-struct lio_info_type Lio_info2[] = {
- { "sync", LIO_IO_SYNC, "sync i/o (read/write)"},
- { "async", LIO_IO_ASYNC, "async i/o (reada/writea/aio_read/aio_write)" },
- { "slistio", LIO_IO_SLISTIO, "single stride sync listio" },
- { "alistio", LIO_IO_ALISTIO, "single stride async listio" },
- { "syncv", LIO_IO_SYNCV, "single buffer sync readv/writev"},
- { "syncp", LIO_IO_SYNCP, "pread/pwrite"},
- { "active", LIO_WAIT_ACTIVE, "spin on status/control values" },
- { "recall", LIO_WAIT_RECALL, "use recall(2)/aio_suspend(3) to wait for i/o to complete" },
- { "sigactive", LIO_WAIT_SIGACTIVE, "spin waiting for signal" },
- { "sigpause", LIO_WAIT_SIGPAUSE, "call pause(2) to wait for signal" },
+struct lio_info_type Lio_info2[] = {
+ {"sync", LIO_IO_SYNC, "sync i/o (read/write)"},
+ {"async", LIO_IO_ASYNC, "async i/o (reada/writea/aio_read/aio_write)"},
+ {"slistio", LIO_IO_SLISTIO, "single stride sync listio"},
+ {"alistio", LIO_IO_ALISTIO, "single stride async listio"},
+ {"syncv", LIO_IO_SYNCV, "single buffer sync readv/writev"},
+ {"syncp", LIO_IO_SYNCP, "pread/pwrite"},
+ {"active", LIO_WAIT_ACTIVE, "spin on status/control values"},
+ {"recall", LIO_WAIT_RECALL,
+ "use recall(2)/aio_suspend(3) to wait for i/o to complete"},
+ {"sigactive", LIO_WAIT_SIGACTIVE, "spin waiting for signal"},
+ {"sigpause", LIO_WAIT_SIGPAUSE, "call pause(2) to wait for signal"},
/* nowait is a touchy thing, it's an accident that this implementation worked at all. 6/27/97 roehrich */
/* { "nowait", LIO_WAIT_NONE, "do not wait for async io to complete" },*/
- { "random", LIO_RANDOM, "set random bit" },
- { "randomall",
- LIO_RANDOM|LIO_IO_TYPES|LIO_WAIT_TYPES,
- "all random i/o types and wait methods (except nowait)" },
+ {"random", LIO_RANDOM, "set random bit"},
+ {"randomall",
+ LIO_RANDOM | LIO_IO_TYPES | LIO_WAIT_TYPES,
+ "all random i/o types and wait methods (except nowait)"},
};
char Lio_SysCall[PATH_MAX]; /* string containing last i/o system call */
@@ -194,8 +202,6 @@
static char Errormsg[500];
static int Debug_level = 0;
-
-
/***********************************************************************
* stride_bounds()
*
@@ -210,16 +216,15 @@
* (maule, 11/16/95)
***********************************************************************/
-int
-stride_bounds(offset, stride, nstrides, bytes_per_stride, min, max)
-int offset;
-int stride;
-int nstrides;
-int bytes_per_stride;
-int *min;
-int *max;
+int stride_bounds(offset, stride, nstrides, bytes_per_stride, min, max)
+int offset;
+int stride;
+int nstrides;
+int bytes_per_stride;
+int *min;
+int *max;
{
- int nbytes, min_byte, max_byte;
+ int nbytes, min_byte, max_byte;
/*
* sanity checks ...
@@ -239,8 +244,7 @@
* bytes referenced.
*/
-
- nbytes = abs(stride) * (nstrides-1) + bytes_per_stride;
+ nbytes = abs(stride) * (nstrides - 1) + bytes_per_stride;
if (stride < 0) {
max_byte = offset + bytes_per_stride - 1;
@@ -264,14 +268,13 @@
/***********************************************************************
* This function will allow someone to set the debug level.
***********************************************************************/
-int
-lio_set_debug(level)
+int lio_set_debug(level)
{
- int old;
+ int old;
- old = Debug_level;
- Debug_level = level;
- return old;
+ old = Debug_level;
+ Debug_level = level;
+ return old;
}
/***********************************************************************
@@ -283,29 +286,29 @@
*
* (rrl 04/96)
***********************************************************************/
-int
-lio_parse_io_arg1(char *string)
+int lio_parse_io_arg1(char *string)
{
- unsigned int ind;
- int found=0;
- int mask=0;
+ unsigned int ind;
+ int found = 0;
+ int mask = 0;
- /*
- * Determine if token is a valid string.
- */
- for (ind=0; ind<sizeof(Lio_info1)/sizeof(struct lio_info_type); ind++) {
- if (strcmp(string, Lio_info1[ind].token) == 0) {
- mask |= Lio_info1[ind].bits;
- found = 1;
- break;
- }
- }
+ /*
+ * Determine if token is a valid string.
+ */
+ for (ind = 0; ind < sizeof(Lio_info1) / sizeof(struct lio_info_type);
+ ind++) {
+ if (strcmp(string, Lio_info1[ind].token) == 0) {
+ mask |= Lio_info1[ind].bits;
+ found = 1;
+ break;
+ }
+ }
- if (found == 0) {
- return -1;
- }
+ if (found == 0) {
+ return -1;
+ }
- return mask;
+ return mask;
}
@@ -315,17 +318,17 @@
* They will be printed one per line.
* (rrl 04/96)
***********************************************************************/
-void
-lio_help1(char *prefix)
+void lio_help1(char *prefix)
{
- unsigned int ind;
+ unsigned int ind;
- for (ind=0; ind<sizeof(Lio_info1)/sizeof(struct lio_info_type); ind++) {
- printf("%s %s : %s\n", prefix,
- Lio_info1[ind].token, Lio_info1[ind].desc);
- }
+ for (ind = 0; ind < sizeof(Lio_info1) / sizeof(struct lio_info_type);
+ ind++) {
+ printf("%s %s : %s\n", prefix, Lio_info1[ind].token,
+ Lio_info1[ind].desc);
+ }
- return;
+ return;
}
/***********************************************************************
@@ -337,67 +340,68 @@
*
* (rrl 04/96)
***********************************************************************/
-int
-lio_parse_io_arg2(char *string, char **badtoken)
+int lio_parse_io_arg2(char *string, char **badtoken)
{
- char *token = string;
- char *cc = token;
- char savecc;
- int found;
- int mask=0;
+ char *token = string;
+ char *cc = token;
+ char savecc;
+ int found;
+ int mask = 0;
- int tmp;
- unsigned int ind;
- char chr;
+ int tmp;
+ unsigned int ind;
+ char chr;
- if (token == NULL)
- return -1;
+ if (token == NULL)
+ return -1;
- for (;;) {
- for (; ((*cc != ',') && (*cc != '\0')); cc++);
- savecc = *cc;
- *cc = '\0';
+ for (;;) {
+ for (; ((*cc != ',') && (*cc != '\0')); cc++) ;
+ savecc = *cc;
+ *cc = '\0';
- found = 0;
+ found = 0;
- /*
- * Determine if token is a valid string or number and if
- * so, add the bits to the mask.
- */
- for (ind=0; ind<sizeof(Lio_info2)/sizeof(struct lio_info_type); ind++) {
- if (strcmp(token, Lio_info2[ind].token) == 0) {
- mask |= Lio_info2[ind].bits;
- found = 1;
- break;
- }
- }
+ /*
+ * Determine if token is a valid string or number and if
+ * so, add the bits to the mask.
+ */
+ for (ind = 0;
+ ind < sizeof(Lio_info2) / sizeof(struct lio_info_type);
+ ind++) {
+ if (strcmp(token, Lio_info2[ind].token) == 0) {
+ mask |= Lio_info2[ind].bits;
+ found = 1;
+ break;
+ }
+ }
- /*
- * If token does not match one of the defined tokens, determine
- * if it is a number, if so, add the bits.
- */
- if (!found) {
- if (sscanf(token, "%i%c", &tmp, &chr) == 1) {
- mask |= tmp;
- found=1;
- }
- }
+ /*
+ * If token does not match one of the defined tokens, determine
+ * if it is a number, if so, add the bits.
+ */
+ if (!found) {
+ if (sscanf(token, "%i%c", &tmp, &chr) == 1) {
+ mask |= tmp;
+ found = 1;
+ }
+ }
- *cc = savecc;
+ *cc = savecc;
- if (!found) { /* token is not valid */
- if (badtoken != NULL)
- *badtoken = token;
- return(-1);
- }
+ if (!found) { /* token is not valid */
+ if (badtoken != NULL)
+ *badtoken = token;
+ return (-1);
+ }
- if (savecc == '\0')
- break;
+ if (savecc == '\0')
+ break;
- token = ++cc;
- }
+ token = ++cc;
+ }
- return mask;
+ return mask;
}
/***********************************************************************
@@ -407,16 +411,16 @@
*
* (rrl 04/96)
***********************************************************************/
-void
-lio_help2(char *prefix)
+void lio_help2(char *prefix)
{
- unsigned int ind;
+ unsigned int ind;
- for (ind=0; ind<sizeof(Lio_info2)/sizeof(struct lio_info_type); ind++) {
- printf("%s %s : %s\n", prefix,
- Lio_info2[ind].token, Lio_info2[ind].desc);
- }
- return;
+ for (ind = 0; ind < sizeof(Lio_info2) / sizeof(struct lio_info_type);
+ ind++) {
+ printf("%s %s : %s\n", prefix, Lio_info2[ind].token,
+ Lio_info2[ind].desc);
+ }
+ return;
}
/***********************************************************************
@@ -424,12 +428,12 @@
* If the handler is called, it will increment the Received_signal
* global variable.
***********************************************************************/
-static void
-lio_async_signal_handler(int sig)
+static void lio_async_signal_handler(int sig)
{
if (Debug_level)
- printf("DEBUG %s/%d: received signal %d, a signal caught %d times\n",
- __FILE__, __LINE__, sig, Received_signal+1);
+ printf
+ ("DEBUG %s/%d: received signal %d, a signal caught %d times\n",
+ __FILE__, __LINE__, sig, Received_signal + 1);
Received_signal++;
@@ -442,12 +446,13 @@
* If the handler is called, it will increment the Received_callback
* global variable.
***********************************************************************/
-static void
-lio_async_callback_handler(sigval_t sigval)
+static void lio_async_callback_handler(sigval_t sigval)
{
if (Debug_level)
- printf("DEBUG %s/%d: received callback, nbytes=%ld, a callback called %d times\n",
- __FILE__, __LINE__, (long)sigval.sival_int, Received_callback+1);
+ printf
+ ("DEBUG %s/%d: received callback, nbytes=%ld, a callback called %d times\n",
+ __FILE__, __LINE__, (long)sigval.sival_int,
+ Received_callback + 1);
Received_callback++;
@@ -469,30 +474,29 @@
*
* (rrl 04/96)
***********************************************************************/
-int
-lio_random_methods(long curr_mask)
+int lio_random_methods(long curr_mask)
{
- int mask=0;
+ int mask = 0;
- /* remove random select, io type, and wait method bits from curr_mask */
- mask = curr_mask & (~(LIO_IO_TYPES | LIO_WAIT_TYPES | LIO_RANDOM));
+ /* remove random select, io type, and wait method bits from curr_mask */
+ mask = curr_mask & (~(LIO_IO_TYPES | LIO_WAIT_TYPES | LIO_RANDOM));
- /* randomly select io type from specified io types */
- mask = mask | random_bit(curr_mask & LIO_IO_TYPES);
+ /* randomly select io type from specified io types */
+ mask = mask | random_bit(curr_mask & LIO_IO_TYPES);
- /* randomly select wait methods from specified wait methods */
- mask = mask | random_bit(curr_mask & LIO_WAIT_TYPES);
+ /* randomly select wait methods from specified wait methods */
+ mask = mask | random_bit(curr_mask & LIO_WAIT_TYPES);
- return mask;
+ return mask;
}
static void wait4sync_io(int fd, int read)
{
- fd_set s;
- FD_ZERO(&s);
- FD_SET(fd, &s);
+ fd_set s;
+ FD_ZERO(&s);
+ FD_SET(fd, &s);
- select(fd+1, read ? &s : NULL, read ? NULL : &s, NULL, NULL);
+ select(fd + 1, read ? &s : NULL, read ? NULL : &s, NULL, NULL);
}
/***********************************************************************
@@ -535,166 +539,168 @@
*
* (rrl 04/96)
***********************************************************************/
-int
-lio_write_buffer(fd, method, buffer, size, sig, errmsg, wrd)
-int fd; /* open file descriptor */
-int method; /* contains io type and wait method bitmask */
-char *buffer; /* pointer to buffer */
-int size; /* the size of the io */
-int sig; /* signal to use if async io */
-char **errmsg; /* char pointer that will be updated to point to err message */
-long wrd; /* to allow future features, use zero for now */
+int lio_write_buffer(fd, method, buffer, size, sig, errmsg, wrd)
+int fd; /* open file descriptor */
+int method; /* contains io type and wait method bitmask */
+char *buffer; /* pointer to buffer */
+int size; /* the size of the io */
+int sig; /* signal to use if async io */
+char **errmsg; /* char pointer that will be updated to point to err message */
+long wrd; /* to allow future features, use zero for now */
{
- int ret = 0; /* syscall return or used to get random method */
- char *io_type; /* Holds string of type of io */
- int omethod = method;
- int listio_cmd; /* Holds the listio/lio_listio cmd */
+ int ret = 0; /* syscall return or used to get random method */
+ char *io_type; /* Holds string of type of io */
+ int omethod = method;
+ int listio_cmd; /* Holds the listio/lio_listio cmd */
#ifdef CRAY
- struct listreq request; /* Used when a listio is wanted */
- struct iosw status, *statptr[1];
+ struct listreq request; /* Used when a listio is wanted */
+ struct iosw status, *statptr[1];
#else
- /* for linux or sgi */
- struct iovec iov; /* iovec for writev(2) */
+ /* for linux or sgi */
+ struct iovec iov; /* iovec for writev(2) */
#endif
#if defined (sgi)
- aiocb_t aiocbp; /* POSIX aio control block */
- aiocb_t *aiolist[1]; /* list of aio control blocks for lio_listio */
- off64_t poffset; /* pwrite(2) offset */
+ aiocb_t aiocbp; /* POSIX aio control block */
+ aiocb_t *aiolist[1]; /* list of aio control blocks for lio_listio */
+ off64_t poffset; /* pwrite(2) offset */
#endif
#if defined(__linux__) && !defined(__UCLIBC__)
struct aiocb aiocbp; /* POSIX aio control block */
- struct aiocb *aiolist[1]; /* list of aio control blocks for lio_listio */
+ struct aiocb *aiolist[1]; /* list of aio control blocks for lio_listio */
off64_t poffset; /* pwrite(2) offset */
#endif
- /*
- * If LIO_RANDOM bit specified, get new method randomly.
- */
- if (method & LIO_RANDOM) {
- if (Debug_level > 3)
- printf("DEBUG %s/%d: method mask to choose from: %#o\n", __FILE__, __LINE__, method );
- method = lio_random_methods(method);
- if (Debug_level > 2)
- printf("DEBUG %s/%d: random chosen method %#o\n", __FILE__, __LINE__, method);
- }
+ /*
+ * If LIO_RANDOM bit specified, get new method randomly.
+ */
+ if (method & LIO_RANDOM) {
+ if (Debug_level > 3)
+ printf("DEBUG %s/%d: method mask to choose from: %#o\n",
+ __FILE__, __LINE__, method);
+ method = lio_random_methods(method);
+ if (Debug_level > 2)
+ printf("DEBUG %s/%d: random chosen method %#o\n",
+ __FILE__, __LINE__, method);
+ }
- if (errmsg != NULL)
- *errmsg = Errormsg;
+ if (errmsg != NULL)
+ *errmsg = Errormsg;
- Rec_signal=Received_signal; /* get the current number of signals received */
+ Rec_signal = Received_signal; /* get the current number of signals received */
#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
- Rec_callback=Received_callback; /* get the current number of callbacks received */
+ Rec_callback = Received_callback; /* get the current number of callbacks received */
#endif
#ifdef CRAY
- memset(&status, 0x00, sizeof(struct iosw));
- memset(&request, 0x00, sizeof(struct listreq));
- statptr[0] = &status;
+ memset(&status, 0x00, sizeof(struct iosw));
+ memset(&request, 0x00, sizeof(struct listreq));
+ statptr[0] = &status;
#else
- /* for linux or sgi */
- memset(&iov, 0x00, sizeof(struct iovec));
- iov.iov_base = buffer;
- iov.iov_len = size;
+ /* for linux or sgi */
+ memset(&iov, 0x00, sizeof(struct iovec));
+ iov.iov_base = buffer;
+ iov.iov_len = size;
#endif
#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
#if defined(sgi)
- memset(&aiocbp, 0x00, sizeof(aiocb_t));
+ memset(&aiocbp, 0x00, sizeof(aiocb_t));
#else
memset(&aiocbp, 0x00, sizeof(struct aiocb));
#endif
- aiocbp.aio_fildes = fd;
- aiocbp.aio_nbytes = size;
- aiocbp.aio_buf = buffer;
+ aiocbp.aio_fildes = fd;
+ aiocbp.aio_nbytes = size;
+ aiocbp.aio_buf = buffer;
/* aiocbp.aio_offset = lseek( fd, 0, SEEK_CUR ); -- set below */
- aiocbp.aio_sigevent.sigev_notify = SIGEV_NONE;
- aiocbp.aio_sigevent.sigev_signo = 0;
+ aiocbp.aio_sigevent.sigev_notify = SIGEV_NONE;
+ aiocbp.aio_sigevent.sigev_signo = 0;
#ifdef sgi
- aiocbp.aio_sigevent.sigev_func = NULL;
- aiocbp.aio_sigevent.sigev_value.sival_int = 0;
+ aiocbp.aio_sigevent.sigev_func = NULL;
+ aiocbp.aio_sigevent.sigev_value.sival_int = 0;
#elif defined(__linux__) && !defined(__UCLIBC__)
aiocbp.aio_sigevent.sigev_notify_function = NULL;
aiocbp.aio_sigevent.sigev_notify_attributes = 0;
#endif
- aiolist[0] = &aiocbp;
+ aiolist[0] = &aiocbp;
- if ((ret = lseek( fd, 0, SEEK_CUR )) == -1) {
- ret = 0;
- /* If there is an error and it is not ESPIPE then kick out the error.
- * If the fd is a fifo then we have to make sure that
- * lio_random_methods() didn't select pwrite/pread; if it did then
- * switch to write/read.
- */
- if (errno == ESPIPE) {
- if (method & LIO_IO_SYNCP) {
- if (omethod & LIO_RANDOM) {
- method &= ~LIO_IO_SYNCP;
- method |= LIO_IO_SYNC;
- if (Debug_level > 2)
- printf("DEBUG %s/%d: random chosen method switched to %#o for fifo\n", __FILE__, __LINE__, method );
+ if ((ret = lseek(fd, 0, SEEK_CUR)) == -1) {
+ ret = 0;
+ /* If there is an error and it is not ESPIPE then kick out the error.
+ * If the fd is a fifo then we have to make sure that
+ * lio_random_methods() didn't select pwrite/pread; if it did then
+ * switch to write/read.
+ */
+ if (errno == ESPIPE) {
+ if (method & LIO_IO_SYNCP) {
+ if (omethod & LIO_RANDOM) {
+ method &= ~LIO_IO_SYNCP;
+ method |= LIO_IO_SYNC;
+ if (Debug_level > 2)
+ printf
+ ("DEBUG %s/%d: random chosen method switched to %#o for fifo\n",
+ __FILE__, __LINE__,
+ method);
+ } else if (Debug_level) {
+ printf
+ ("DEBUG %s/%d: pwrite will fail when it writes to a fifo\n",
+ __FILE__, __LINE__);
+ }
}
- else if (Debug_level) {
- printf("DEBUG %s/%d: pwrite will fail when it writes to a fifo\n",
- __FILE__, __LINE__ );
- }
+ /* else: let it ride */
+ } else {
+ sprintf(Errormsg,
+ "%s/%d lseek(fd=%d,0,SEEK_CUR) failed, errno=%d %s",
+ __FILE__, __LINE__, fd, errno, strerror(errno));
+ return -errno;
}
- /* else: let it ride */
}
- else{
- sprintf(Errormsg, "%s/%d lseek(fd=%d,0,SEEK_CUR) failed, errno=%d %s",
- __FILE__, __LINE__, fd, errno, strerror(errno));
- return -errno;
- }
- }
#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
- poffset = (off64_t)ret;
+ poffset = (off64_t) ret;
#endif
- aiocbp.aio_offset = ret;
+ aiocbp.aio_offset = ret;
#endif
- /*
- * If the LIO_USE_SIGNAL bit is not set, only use the signal
- * if the LIO_WAIT_SIGPAUSE or the LIO_WAIT_SIGACTIVE bits are bit.
- * Otherwise there is not necessary a signal handler to trap
- * the signal.
- */
- if (sig && !(method & LIO_USE_SIGNAL) &&
- ! (method & LIO_WAIT_SIGTYPES) ) {
-
- sig=0; /* ignore signal parameter */
- }
-
-#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
- if (sig && (method & LIO_WAIT_CBTYPES))
- sig=0; /* ignore signal parameter */
-#endif
-
- /*
- * only setup signal hander if sig was specified and
- * a sig wait method was specified.
- * Doing this will change the handler for this signal. The
- * old signal handler will not be restored.
- *** restoring the signal handler could be added ***
- */
-
- if (sig && (method & LIO_WAIT_SIGTYPES)) {
-#ifdef CRAY
- sigctl(SCTL_REG, sig, lio_async_signal_handler);
-#endif
-#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
- aiocbp.aio_sigevent.sigev_notify = SIGEV_SIGNAL;
- aiocbp.aio_sigevent.sigev_signo = sig;
- sigset(sig, lio_async_signal_handler);
-#endif /* sgi */
- }
-#if defined(sgi)
- else if (method & LIO_WAIT_CBTYPES) {
- /* sival_int just has to be something that I can use
- * to identify the callback, and "size" happens to be handy...
+ /*
+ * If the LIO_USE_SIGNAL bit is not set, only use the signal
+ * if the LIO_WAIT_SIGPAUSE or the LIO_WAIT_SIGACTIVE bits are bit.
+ * Otherwise there is not necessary a signal handler to trap
+ * the signal.
*/
- aiocbp.aio_sigevent.sigev_notify = SIGEV_CALLBACK;
- aiocbp.aio_sigevent.sigev_func = lio_async_callback_handler;
- aiocbp.aio_sigevent.sigev_value.sival_int = size;
- }
+ if (sig && !(method & LIO_USE_SIGNAL) && !(method & LIO_WAIT_SIGTYPES)) {
+
+ sig = 0; /* ignore signal parameter */
+ }
+#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+ if (sig && (method & LIO_WAIT_CBTYPES))
+ sig = 0; /* ignore signal parameter */
+#endif
+
+ /*
+ * only setup signal hander if sig was specified and
+ * a sig wait method was specified.
+ * Doing this will change the handler for this signal. The
+ * old signal handler will not be restored.
+ *** restoring the signal handler could be added ***
+ */
+
+ if (sig && (method & LIO_WAIT_SIGTYPES)) {
+#ifdef CRAY
+ sigctl(SCTL_REG, sig, lio_async_signal_handler);
+#endif
+#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+ aiocbp.aio_sigevent.sigev_notify = SIGEV_SIGNAL;
+ aiocbp.aio_sigevent.sigev_signo = sig;
+ sigset(sig, lio_async_signal_handler);
+#endif /* sgi */
+ }
+#if defined(sgi)
+ else if (method & LIO_WAIT_CBTYPES) {
+ /* sival_int just has to be something that I can use
+ * to identify the callback, and "size" happens to be handy...
+ */
+ aiocbp.aio_sigevent.sigev_notify = SIGEV_CALLBACK;
+ aiocbp.aio_sigevent.sigev_func = lio_async_callback_handler;
+ aiocbp.aio_sigevent.sigev_value.sival_int = size;
+ }
#endif
#if defined(__linux__) && !defined(__UCLIBC__)
else if (method & LIO_WAIT_CBTYPES) {
@@ -702,347 +708,367 @@
* to identify the callback, and "size" happens to be handy...
*/
aiocbp.aio_sigevent.sigev_notify = SIGEV_THREAD;
- aiocbp.aio_sigevent.sigev_notify_function = lio_async_callback_handler;
- aiocbp.aio_sigevent.sigev_notify_attributes = (void*)(uintptr_t)size;
+ aiocbp.aio_sigevent.sigev_notify_function =
+ lio_async_callback_handler;
+ aiocbp.aio_sigevent.sigev_notify_attributes =
+ (void *)(uintptr_t) size;
}
#endif
- /*
- * Determine the system call that will be called and produce
- * the string of the system call and place it in Lio_SysCall.
- * Also update the io_type char pointer to give brief description
- * of system call. Execute the system call and check for
- * system call failure. If sync i/o, return the number of
- * bytes written/read.
- */
-
- if ((method & LIO_IO_SYNC) || (method & (LIO_IO_TYPES | LIO_IO_ATYPES)) == 0) {
/*
- * write(2) is used if LIO_IO_SYNC bit is set or not none
- * of the LIO_IO_TYPES bits are set (default).
- */
+ * Determine the system call that will be called and produce
+ * the string of the system call and place it in Lio_SysCall.
+ * Also update the io_type char pointer to give brief description
+ * of system call. Execute the system call and check for
+ * system call failure. If sync i/o, return the number of
+ * bytes written/read.
+ */
- sprintf(Lio_SysCall,
- "write(%d, buf, %d)", fd, size);
- io_type="write";
+ if ((method & LIO_IO_SYNC)
+ || (method & (LIO_IO_TYPES | LIO_IO_ATYPES)) == 0) {
+ /*
+ * write(2) is used if LIO_IO_SYNC bit is set or not none
+ * of the LIO_IO_TYPES bits are set (default).
+ */
- if (Debug_level) {
- printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__, Lio_SysCall);
- }
- while (1) {
- if (((ret = write(fd, buffer, size)) == -1) && errno!=EAGAIN && errno!=EINTR) {
- sprintf(Errormsg, "%s/%d write(%d, buf, %d) ret:-1, errno=%d %s",
- __FILE__, __LINE__,
- fd, size, errno, strerror(errno));
- return -errno;
- }
+ sprintf(Lio_SysCall, "write(%d, buf, %d)", fd, size);
+ io_type = "write";
- if (ret!=-1) {
- if (ret != size) {
- sprintf(Errormsg,
- "%s/%d write(%d, buf, %d) returned=%d",
- __FILE__, __LINE__,
- fd, size, ret);
- size-=ret;
- buffer+=ret;
- }
- else {
- if (Debug_level > 1)
- printf("DEBUG %s/%d: write completed without error (ret %d)\n",
- __FILE__, __LINE__, ret);
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
+ while (1) {
+ if (((ret = write(fd, buffer, size)) == -1)
+ && errno != EAGAIN && errno != EINTR) {
+ sprintf(Errormsg,
+ "%s/%d write(%d, buf, %d) ret:-1, errno=%d %s",
+ __FILE__, __LINE__, fd, size, errno,
+ strerror(errno));
+ return -errno;
+ }
- return ret;
- }
- }
- wait4sync_io(fd, 0);
- }
+ if (ret != -1) {
+ if (ret != size) {
+ sprintf(Errormsg,
+ "%s/%d write(%d, buf, %d) returned=%d",
+ __FILE__, __LINE__,
+ fd, size, ret);
+ size -= ret;
+ buffer += ret;
+ } else {
+ if (Debug_level > 1)
+ printf
+ ("DEBUG %s/%d: write completed without error (ret %d)\n",
+ __FILE__, __LINE__, ret);
- }
+ return ret;
+ }
+ }
+ wait4sync_io(fd, 0);
+ }
- else if (method & LIO_IO_ASYNC) {
-#ifdef CRAY
- sprintf(Lio_SysCall,
- "writea(%d, buf, %d, &status, %d)", fd, size, sig);
- io_type="writea";
-
- if (Debug_level) {
- printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__, Lio_SysCall);
- }
-
- sigoff();
- if ((ret = writea(fd, buffer, size, &status, sig)) == -1) {
- sprintf(Errormsg,
- "%s/%d writea(%d, buf, %d, &stat, %d) ret:-1, errno=%d %s",
- __FILE__, __LINE__,
- fd, size, sig, errno, strerror(errno));
- sigon();
- return -errno;
}
+
+ else if (method & LIO_IO_ASYNC) {
+#ifdef CRAY
+ sprintf(Lio_SysCall,
+ "writea(%d, buf, %d, &status, %d)", fd, size, sig);
+ io_type = "writea";
+
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
+
+ sigoff();
+ if ((ret = writea(fd, buffer, size, &status, sig)) == -1) {
+ sprintf(Errormsg,
+ "%s/%d writea(%d, buf, %d, &stat, %d) ret:-1, errno=%d %s",
+ __FILE__, __LINE__,
+ fd, size, sig, errno, strerror(errno));
+ sigon();
+ return -errno;
+ }
#endif
#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
- sprintf(Lio_SysCall,
- "aio_write(fildes=%d, buf, nbytes=%d, signo=%d)", fd, size, sig);
- io_type="aio_write";
+ sprintf(Lio_SysCall,
+ "aio_write(fildes=%d, buf, nbytes=%d, signo=%d)", fd,
+ size, sig);
+ io_type = "aio_write";
- if (Debug_level) {
- printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__, Lio_SysCall);
- }
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
- if (sig)
- sighold( sig );
- if ((ret = aio_write(&aiocbp)) == -1) {
- sprintf(Errormsg,
- "%s/%d aio_write(fildes=%d, buf, nbytes=%d, signo=%d) ret:-1, errno=%d %s",
- __FILE__, __LINE__,
- fd, size, sig, errno, strerror(errno));
- if (sig)
- sigrelse( sig );
- return -errno;
- }
+ if (sig)
+ sighold(sig);
+ if ((ret = aio_write(&aiocbp)) == -1) {
+ sprintf(Errormsg,
+ "%s/%d aio_write(fildes=%d, buf, nbytes=%d, signo=%d) ret:-1, errno=%d %s",
+ __FILE__, __LINE__,
+ fd, size, sig, errno, strerror(errno));
+ if (sig)
+ sigrelse(sig);
+ return -errno;
+ }
#endif
- } /* LIO_IO_ASYNC */
-
- else if (method & LIO_IO_SLISTIO) {
+ }
+ /* LIO_IO_ASYNC */
+ else if (method & LIO_IO_SLISTIO) {
#ifdef CRAY
- request.li_opcode = LO_WRITE;
- request.li_fildes = fd;
- request.li_buf = buffer;
- request.li_nbyte = size;
- request.li_status = &status;
- request.li_signo = sig;
- request.li_nstride = 0;
- request.li_filstride = 0;
- request.li_memstride = 0;
+ request.li_opcode = LO_WRITE;
+ request.li_fildes = fd;
+ request.li_buf = buffer;
+ request.li_nbyte = size;
+ request.li_status = &status;
+ request.li_signo = sig;
+ request.li_nstride = 0;
+ request.li_filstride = 0;
+ request.li_memstride = 0;
- listio_cmd=LC_WAIT;
- io_type="listio(2) sync write";
+ listio_cmd = LC_WAIT;
+ io_type = "listio(2) sync write";
- sprintf(Lio_SysCall,
- "listio(LC_WAIT, &req, 1) LO_WRITE, fd:%d, nbyte:%d",
- fd, size);
+ sprintf(Lio_SysCall,
+ "listio(LC_WAIT, &req, 1) LO_WRITE, fd:%d, nbyte:%d",
+ fd, size);
- if (Debug_level) {
- printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__, Lio_SysCall);
- }
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
- sigoff();
- if (listio(listio_cmd, &request, 1) == -1) {
- sprintf(Errormsg, "%s/%d %s failed, fd:%d, nbyte:%d errno=%d %s",
- __FILE__, __LINE__,
- Lio_SysCall, fd, size, errno, strerror(errno));
- sigon();
- return -errno;
- }
+ sigoff();
+ if (listio(listio_cmd, &request, 1) == -1) {
+ sprintf(Errormsg,
+ "%s/%d %s failed, fd:%d, nbyte:%d errno=%d %s",
+ __FILE__, __LINE__, Lio_SysCall, fd, size,
+ errno, strerror(errno));
+ sigon();
+ return -errno;
+ }
- if (Debug_level > 1)
- printf("DEBUG %s/%d: %s did not return -1\n",
- __FILE__, __LINE__, Lio_SysCall);
+ if (Debug_level > 1)
+ printf("DEBUG %s/%d: %s did not return -1\n",
+ __FILE__, __LINE__, Lio_SysCall);
- ret=lio_check_asyncio(io_type, size, &status);
- return ret;
+ ret = lio_check_asyncio(io_type, size, &status);
+ return ret;
#endif
#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
- aiocbp.aio_lio_opcode = LIO_WRITE;
- listio_cmd=LIO_WAIT;
- io_type="lio_listio(3) sync write";
+ aiocbp.aio_lio_opcode = LIO_WRITE;
+ listio_cmd = LIO_WAIT;
+ io_type = "lio_listio(3) sync write";
- sprintf(Lio_SysCall,
- "lio_listio(LIO_WAIT, aiolist, 1, NULL) LIO_WRITE, fd:%d, nbyte:%d, sig:%d",
- fd, size, sig );
+ sprintf(Lio_SysCall,
+ "lio_listio(LIO_WAIT, aiolist, 1, NULL) LIO_WRITE, fd:%d, nbyte:%d, sig:%d",
+ fd, size, sig);
- if (Debug_level) {
- printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__, Lio_SysCall);
- }
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
- if (sig)
- sighold( sig );
- if (lio_listio(listio_cmd, aiolist, 1, NULL) == -1) {
- sprintf(Errormsg, "%s/%d %s failed, fd:%d, nbyte:%d errno=%d %s",
- __FILE__, __LINE__,
- Lio_SysCall, fd, size, errno, strerror(errno));
- if (sig)
- sigrelse( sig );
- return -errno;
- }
+ if (sig)
+ sighold(sig);
+ if (lio_listio(listio_cmd, aiolist, 1, NULL) == -1) {
+ sprintf(Errormsg,
+ "%s/%d %s failed, fd:%d, nbyte:%d errno=%d %s",
+ __FILE__, __LINE__, Lio_SysCall, fd, size,
+ errno, strerror(errno));
+ if (sig)
+ sigrelse(sig);
+ return -errno;
+ }
- if (Debug_level > 1)
- printf("DEBUG %s/%d: %s did not return -1\n",
- __FILE__, __LINE__, Lio_SysCall);
+ if (Debug_level > 1)
+ printf("DEBUG %s/%d: %s did not return -1\n",
+ __FILE__, __LINE__, Lio_SysCall);
- ret=lio_check_asyncio(io_type, size, &aiocbp, method);
- return ret;
+ ret = lio_check_asyncio(io_type, size, &aiocbp, method);
+ return ret;
#endif
- } /* LIO_IO_SLISTIO */
-
- else if (method & LIO_IO_ALISTIO) {
+ }
+ /* LIO_IO_SLISTIO */
+ else if (method & LIO_IO_ALISTIO) {
#ifdef CRAY
- request.li_opcode = LO_WRITE;
- request.li_fildes = fd;
- request.li_buf = buffer;
- request.li_nbyte = size;
- request.li_status = &status;
- request.li_signo = sig;
- request.li_nstride = 0;
- request.li_filstride = 0;
- request.li_memstride = 0;
+ request.li_opcode = LO_WRITE;
+ request.li_fildes = fd;
+ request.li_buf = buffer;
+ request.li_nbyte = size;
+ request.li_status = &status;
+ request.li_signo = sig;
+ request.li_nstride = 0;
+ request.li_filstride = 0;
+ request.li_memstride = 0;
- listio_cmd=LC_START;
- io_type="listio(2) async write";
+ listio_cmd = LC_START;
+ io_type = "listio(2) async write";
- sprintf(Lio_SysCall,
- "listio(LC_START, &req, 1) LO_WRITE, fd:%d, nbyte:%d",
- fd, size);
+ sprintf(Lio_SysCall,
+ "listio(LC_START, &req, 1) LO_WRITE, fd:%d, nbyte:%d",
+ fd, size);
- if (Debug_level) {
- printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__, Lio_SysCall);
- }
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
- sigoff();
- if (listio(listio_cmd, &request, 1) == -1) {
- sprintf(Errormsg, "%s/%d %s failed, fd:%d, nbyte:%d errno=%d %s",
- __FILE__, __LINE__,
- Lio_SysCall, fd, size, errno, strerror(errno));
- sigon();
- return -errno;
- }
+ sigoff();
+ if (listio(listio_cmd, &request, 1) == -1) {
+ sprintf(Errormsg,
+ "%s/%d %s failed, fd:%d, nbyte:%d errno=%d %s",
+ __FILE__, __LINE__, Lio_SysCall, fd, size,
+ errno, strerror(errno));
+ sigon();
+ return -errno;
+ }
#endif
#if defined (sgi) || (defined(__linux__) && !defined(__UCLIBC__))
- aiocbp.aio_lio_opcode = LIO_WRITE;
- listio_cmd=LIO_NOWAIT;
- io_type="lio_listio(3) async write";
+ aiocbp.aio_lio_opcode = LIO_WRITE;
+ listio_cmd = LIO_NOWAIT;
+ io_type = "lio_listio(3) async write";
- sprintf(Lio_SysCall,
- "lio_listio(LIO_NOWAIT, aiolist, 1, NULL) LIO_WRITE, fd:%d, nbyte:%d",
- fd, size);
+ sprintf(Lio_SysCall,
+ "lio_listio(LIO_NOWAIT, aiolist, 1, NULL) LIO_WRITE, fd:%d, nbyte:%d",
+ fd, size);
- if (Debug_level) {
- printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__, Lio_SysCall);
- }
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
- if (sig)
- sighold( sig );
- if (lio_listio(listio_cmd, aiolist, 1, NULL) == -1) {
- sprintf(Errormsg, "%s/%d %s failed, fd:%d, nbyte:%d errno=%d %s",
- __FILE__, __LINE__,
- Lio_SysCall, fd, size, errno, strerror(errno));
- if (sig)
- sigrelse( sig );
- return -errno;
- }
+ if (sig)
+ sighold(sig);
+ if (lio_listio(listio_cmd, aiolist, 1, NULL) == -1) {
+ sprintf(Errormsg,
+ "%s/%d %s failed, fd:%d, nbyte:%d errno=%d %s",
+ __FILE__, __LINE__, Lio_SysCall, fd, size,
+ errno, strerror(errno));
+ if (sig)
+ sigrelse(sig);
+ return -errno;
+ }
#endif
- }/* LIO_IO_ALISTIO */
-
+ }
+ /* LIO_IO_ALISTIO */
#ifndef CRAY
- else if (method & LIO_IO_SYNCV) {
- io_type="writev(2)";
+ else if (method & LIO_IO_SYNCV) {
+ io_type = "writev(2)";
- sprintf(Lio_SysCall,
- "writev(%d, &iov, 1) nbyte:%d", fd, size);
+ sprintf(Lio_SysCall, "writev(%d, &iov, 1) nbyte:%d", fd, size);
- if (Debug_level) {
- printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__, Lio_SysCall);
- }
- if ((ret = writev(fd, &iov, 1)) == -1) {
- sprintf(Errormsg, "%s/%d writev(%d, iov, 1) nbyte:%d ret:-1, errno=%d %s",
- __FILE__, __LINE__,
- fd, size, errno, strerror(errno));
- return -errno;
- }
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
+ if ((ret = writev(fd, &iov, 1)) == -1) {
+ sprintf(Errormsg,
+ "%s/%d writev(%d, iov, 1) nbyte:%d ret:-1, errno=%d %s",
+ __FILE__, __LINE__, fd, size, errno,
+ strerror(errno));
+ return -errno;
+ }
- if (ret != size) {
- sprintf(Errormsg,
- "%s/%d writev(%d, iov, 1) nbyte:%d returned=%d",
- __FILE__, __LINE__,
- fd, size, ret);
- }
- else if (Debug_level > 1)
- printf("DEBUG %s/%d: writev completed without error (ret %d)\n",
- __FILE__, __LINE__, ret);
+ if (ret != size) {
+ sprintf(Errormsg,
+ "%s/%d writev(%d, iov, 1) nbyte:%d returned=%d",
+ __FILE__, __LINE__, fd, size, ret);
+ } else if (Debug_level > 1)
+ printf
+ ("DEBUG %s/%d: writev completed without error (ret %d)\n",
+ __FILE__, __LINE__, ret);
- return ret;
- } /* LIO_IO_SYNCV */
+ return ret;
+ } /* LIO_IO_SYNCV */
#endif
#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
- else if (method & LIO_IO_SYNCP) {
- io_type="pwrite(2)";
+ else if (method & LIO_IO_SYNCP) {
+ io_type = "pwrite(2)";
- sprintf(Lio_SysCall,
- "pwrite(%d, buf, %d, %lld)", fd, size, (long long)poffset);
+ sprintf(Lio_SysCall,
+ "pwrite(%d, buf, %d, %lld)", fd, size,
+ (long long)poffset);
- if (Debug_level) {
- printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__, Lio_SysCall);
- }
- if ((ret = pwrite(fd, buffer, size, poffset)) == -1) {
- sprintf(Errormsg, "%s/%d pwrite(%d, buf, %d, %lld) ret:-1, errno=%d %s",
- __FILE__, __LINE__,
- fd, size, (long long)poffset, errno, strerror(errno));
- return -errno;
- }
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
+ if ((ret = pwrite(fd, buffer, size, poffset)) == -1) {
+ sprintf(Errormsg,
+ "%s/%d pwrite(%d, buf, %d, %lld) ret:-1, errno=%d %s",
+ __FILE__, __LINE__, fd, size,
+ (long long)poffset, errno, strerror(errno));
+ return -errno;
+ }
- if (ret != size) {
- sprintf(Errormsg,
- "%s/%d pwrite(%d, buf, %d, %lld) returned=%d",
- __FILE__, __LINE__,
- fd, size, (long long)poffset, ret);
- }
- else if (Debug_level > 1)
- printf("DEBUG %s/%d: pwrite completed without error (ret %d)\n",
- __FILE__, __LINE__, ret);
+ if (ret != size) {
+ sprintf(Errormsg,
+ "%s/%d pwrite(%d, buf, %d, %lld) returned=%d",
+ __FILE__, __LINE__,
+ fd, size, (long long)poffset, ret);
+ } else if (Debug_level > 1)
+ printf
+ ("DEBUG %s/%d: pwrite completed without error (ret %d)\n",
+ __FILE__, __LINE__, ret);
- return ret;
- } /* LIO_IO_SYNCP */
+ return ret;
+ } /* LIO_IO_SYNCP */
#endif
- else {
- printf("DEBUG %s/%d: No I/O method chosen\n", __FILE__, __LINE__ );
- return -1;
- }
+ else {
+ printf("DEBUG %s/%d: No I/O method chosen\n", __FILE__,
+ __LINE__);
+ return -1;
+ }
- /*
- * wait for async io to complete.
- */
+ /*
+ * wait for async io to complete.
+ */
#ifdef CRAY
- ret=lio_wait4asyncio(method, fd, statptr);
+ ret = lio_wait4asyncio(method, fd, statptr);
#endif
#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
- ret=lio_wait4asyncio(method, fd, &aiocbp);
+ ret = lio_wait4asyncio(method, fd, &aiocbp);
#endif
- /*
- * If there was an error waiting for async i/o to complete,
- * return the error value (errno) to the caller.
- * Note: Errormsg should already have been updated.
- */
- if (ret < 0) {
+ /*
+ * If there was an error waiting for async i/o to complete,
+ * return the error value (errno) to the caller.
+ * Note: Errormsg should already have been updated.
+ */
+ if (ret < 0) {
+ return ret;
+ }
+
+ /*
+ * If i/o was not waited for (may not have been completed at this time),
+ * return the size that was requested.
+ */
+ if (ret == 1)
+ return size;
+
+ /*
+ * check that async io was successful.
+ * Note: if the there was an system call failure, -errno
+ * was returned and Errormsg should already have been updated.
+ * If amount i/o was different than size, Errormsg should already
+ * have been updated but the actual i/o size if returned.
+ */
+
+#ifdef CRAY
+ ret = lio_check_asyncio(io_type, size, &status);
+#endif
+#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+ ret = lio_check_asyncio(io_type, size, &aiocbp, method);
+#endif
+
return ret;
- }
-
- /*
- * If i/o was not waited for (may not have been completed at this time),
- * return the size that was requested.
- */
- if (ret == 1)
- return size;
-
- /*
- * check that async io was successful.
- * Note: if the there was an system call failure, -errno
- * was returned and Errormsg should already have been updated.
- * If amount i/o was different than size, Errormsg should already
- * have been updated but the actual i/o size if returned.
- */
-
-#ifdef CRAY
- ret=lio_check_asyncio(io_type, size, &status);
-#endif
-#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
- ret=lio_check_asyncio(io_type, size, &aiocbp, method);
-#endif
-
- return ret;
-} /* end of lio_write_buffer */
+} /* end of lio_write_buffer */
/***********************************************************************
* Generic read function
@@ -1084,518 +1110,540 @@
*
* (rrl 04/96)
***********************************************************************/
-int
-lio_read_buffer(fd, method, buffer, size, sig, errmsg, wrd)
-int fd; /* open file descriptor */
-int method; /* contains io type and wait method bitmask */
-char *buffer; /* pointer to buffer */
-int size; /* the size of the io */
-int sig; /* signal to use if async io */
-char **errmsg; /* char pointer that will be updated to point to err message */
-long wrd; /* to allow future features, use zero for now */
+int lio_read_buffer(fd, method, buffer, size, sig, errmsg, wrd)
+int fd; /* open file descriptor */
+int method; /* contains io type and wait method bitmask */
+char *buffer; /* pointer to buffer */
+int size; /* the size of the io */
+int sig; /* signal to use if async io */
+char **errmsg; /* char pointer that will be updated to point to err message */
+long wrd; /* to allow future features, use zero for now */
{
- int ret = 0; /* syscall return or used to get random method */
- char *io_type; /* Holds string of type of io */
- int listio_cmd; /* Holds the listio/lio_listio cmd */
- int omethod = method;
+ int ret = 0; /* syscall return or used to get random method */
+ char *io_type; /* Holds string of type of io */
+ int listio_cmd; /* Holds the listio/lio_listio cmd */
+ int omethod = method;
#ifdef CRAY
- struct listreq request; /* Used when a listio is wanted */
- struct iosw status, *statptr[1];
+ struct listreq request; /* Used when a listio is wanted */
+ struct iosw status, *statptr[1];
#else
- /* for linux or sgi */
- struct iovec iov; /* iovec for readv(2) */
+ /* for linux or sgi */
+ struct iovec iov; /* iovec for readv(2) */
#endif
#ifdef sgi
- aiocb_t aiocbp; /* POSIX aio control block */
- aiocb_t *aiolist[1]; /* list of aio control blocks for lio_listio */
- off64_t poffset; /* pread(2) offset */
+ aiocb_t aiocbp; /* POSIX aio control block */
+ aiocb_t *aiolist[1]; /* list of aio control blocks for lio_listio */
+ off64_t poffset; /* pread(2) offset */
#endif
#if defined (__linux__) && !defined(__UCLIBC__)
struct aiocb aiocbp; /* POSIX aio control block */
- struct aiocb *aiolist[1]; /* list of aio control blocks for lio_listio */
+ struct aiocb *aiolist[1]; /* list of aio control blocks for lio_listio */
off64_t poffset; /* pread(2) offset */
#endif
- /*
- * If LIO_RANDOM bit specified, get new method randomly.
- */
- if (method & LIO_RANDOM) {
- if (Debug_level > 3)
- printf("DEBUG %s/%d: method mask to choose from: %#o\n", __FILE__, __LINE__, method );
- method = lio_random_methods(method);
- if (Debug_level > 2)
- printf("DEBUG %s/%d: random chosen method %#o\n", __FILE__, __LINE__, method);
- }
+ /*
+ * If LIO_RANDOM bit specified, get new method randomly.
+ */
+ if (method & LIO_RANDOM) {
+ if (Debug_level > 3)
+ printf("DEBUG %s/%d: method mask to choose from: %#o\n",
+ __FILE__, __LINE__, method);
+ method = lio_random_methods(method);
+ if (Debug_level > 2)
+ printf("DEBUG %s/%d: random chosen method %#o\n",
+ __FILE__, __LINE__, method);
+ }
- if (errmsg != NULL)
- *errmsg = Errormsg;
+ if (errmsg != NULL)
+ *errmsg = Errormsg;
- Rec_signal=Received_signal; /* get the current number of signals received */
+ Rec_signal = Received_signal; /* get the current number of signals received */
#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
- Rec_callback=Received_callback; /* get the current number of callbacks received */
+ Rec_callback = Received_callback; /* get the current number of callbacks received */
#endif
#ifdef CRAY
- memset(&status, 0x00, sizeof(struct iosw));
- memset(&request, 0x00, sizeof(struct listreq));
- statptr[0] = &status;
+ memset(&status, 0x00, sizeof(struct iosw));
+ memset(&request, 0x00, sizeof(struct listreq));
+ statptr[0] = &status;
#else
- /* for linux or sgi */
- memset(&iov, 0x00, sizeof(struct iovec));
- iov.iov_base = buffer;
- iov.iov_len = size;
+ /* for linux or sgi */
+ memset(&iov, 0x00, sizeof(struct iovec));
+ iov.iov_base = buffer;
+ iov.iov_len = size;
#endif
#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
#if defined(sgi)
- memset(&aiocbp, 0x00, sizeof(aiocb_t));
+ memset(&aiocbp, 0x00, sizeof(aiocb_t));
#else
memset(&aiocbp, 0x00, sizeof(struct aiocb));
#endif
- aiocbp.aio_fildes = fd;
- aiocbp.aio_nbytes = size;
- aiocbp.aio_buf = buffer;
+ aiocbp.aio_fildes = fd;
+ aiocbp.aio_nbytes = size;
+ aiocbp.aio_buf = buffer;
/* aiocbp.aio_offset = lseek( fd, 0, SEEK_CUR ); -- set below */
- aiocbp.aio_sigevent.sigev_notify = SIGEV_NONE;
- aiocbp.aio_sigevent.sigev_signo = 0;
+ aiocbp.aio_sigevent.sigev_notify = SIGEV_NONE;
+ aiocbp.aio_sigevent.sigev_signo = 0;
#ifdef sgi
- aiocbp.aio_sigevent.sigev_func = NULL;
- aiocbp.aio_sigevent.sigev_value.sival_int = 0;
+ aiocbp.aio_sigevent.sigev_func = NULL;
+ aiocbp.aio_sigevent.sigev_value.sival_int = 0;
#elif defined(__linux__) && !defined(__UCLIBC__)
aiocbp.aio_sigevent.sigev_notify_function = NULL;
aiocbp.aio_sigevent.sigev_notify_attributes = 0;
#endif
- aiolist[0] = &aiocbp;
+ aiolist[0] = &aiocbp;
- if ((ret = lseek( fd, 0, SEEK_CUR )) == -1) {
- ret = 0;
- /* If there is an error and it is not ESPIPE then kick out the error.
- * If the fd is a fifo then we have to make sure that
- * lio_random_methods() didn't select pwrite/pread; if it did then
- * switch to write/read.
- */
- if (errno == ESPIPE) {
- if (method & LIO_IO_SYNCP) {
- if (omethod & LIO_RANDOM) {
- method &= ~LIO_IO_SYNCP;
- method |= LIO_IO_SYNC;
- if (Debug_level > 2)
- printf("DEBUG %s/%d: random chosen method switched to %#o for fifo\n", __FILE__, __LINE__, method );
+ if ((ret = lseek(fd, 0, SEEK_CUR)) == -1) {
+ ret = 0;
+ /* If there is an error and it is not ESPIPE then kick out the error.
+ * If the fd is a fifo then we have to make sure that
+ * lio_random_methods() didn't select pwrite/pread; if it did then
+ * switch to write/read.
+ */
+ if (errno == ESPIPE) {
+ if (method & LIO_IO_SYNCP) {
+ if (omethod & LIO_RANDOM) {
+ method &= ~LIO_IO_SYNCP;
+ method |= LIO_IO_SYNC;
+ if (Debug_level > 2)
+ printf
+ ("DEBUG %s/%d: random chosen method switched to %#o for fifo\n",
+ __FILE__, __LINE__,
+ method);
+ } else if (Debug_level) {
+ printf
+ ("DEBUG %s/%d: pread will fail when it reads from a fifo\n",
+ __FILE__, __LINE__);
+ }
}
- else if (Debug_level) {
- printf("DEBUG %s/%d: pread will fail when it reads from a fifo\n",
- __FILE__, __LINE__ );
- }
+ /* else: let it ride */
+ } else {
+ sprintf(Errormsg,
+ "%s/%d lseek(fd=%d,0,SEEK_CUR) failed, errno=%d %s",
+ __FILE__, __LINE__, fd, errno, strerror(errno));
+ return -errno;
}
- /* else: let it ride */
}
- else{
- sprintf(Errormsg, "%s/%d lseek(fd=%d,0,SEEK_CUR) failed, errno=%d %s",
- __FILE__, __LINE__, fd, errno, strerror(errno));
- return -errno;
- }
- }
#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
- poffset = (off64_t)ret;
+ poffset = (off64_t) ret;
#endif
- aiocbp.aio_offset = ret;
+ aiocbp.aio_offset = ret;
#endif
- /*
- * If the LIO_USE_SIGNAL bit is not set, only use the signal
- * if the LIO_WAIT_SIGPAUSE or the LIO_WAIT_SIGACTIVE bits are set.
- * Otherwise there is not necessarily a signal handler to trap
- * the signal.
- */
- if (sig && !(method & LIO_USE_SIGNAL) &&
- ! (method & LIO_WAIT_SIGTYPES) ) {
+ /*
+ * If the LIO_USE_SIGNAL bit is not set, only use the signal
+ * if the LIO_WAIT_SIGPAUSE or the LIO_WAIT_SIGACTIVE bits are set.
+ * Otherwise there is not necessarily a signal handler to trap
+ * the signal.
+ */
+ if (sig && !(method & LIO_USE_SIGNAL) && !(method & LIO_WAIT_SIGTYPES)) {
- sig=0; /* ignore signal parameter */
- }
-
+ sig = 0; /* ignore signal parameter */
+ }
#if defined(sgi) || (defined(__linux__)&& !defined(__UCLIBC__))
- if (sig && (method & LIO_WAIT_CBTYPES))
- sig=0; /* ignore signal parameter */
+ if (sig && (method & LIO_WAIT_CBTYPES))
+ sig = 0; /* ignore signal parameter */
#endif
- /*
- * only setup signal hander if sig was specified and
- * a sig wait method was specified.
- * Doing this will change the handler for this signal. The
- * old signal handler will not be restored.
- *** restoring the signal handler could be added ***
- */
+ /*
+ * only setup signal hander if sig was specified and
+ * a sig wait method was specified.
+ * Doing this will change the handler for this signal. The
+ * old signal handler will not be restored.
+ *** restoring the signal handler could be added ***
+ */
- if (sig && (method & LIO_WAIT_SIGTYPES)) {
+ if (sig && (method & LIO_WAIT_SIGTYPES)) {
#ifdef CRAY
- sigctl(SCTL_REG, sig, lio_async_signal_handler);
+ sigctl(SCTL_REG, sig, lio_async_signal_handler);
#endif
#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
- aiocbp.aio_sigevent.sigev_notify = SIGEV_SIGNAL;
- aiocbp.aio_sigevent.sigev_signo = sig;
- sigset(sig, lio_async_signal_handler);
+ aiocbp.aio_sigevent.sigev_notify = SIGEV_SIGNAL;
+ aiocbp.aio_sigevent.sigev_signo = sig;
+ sigset(sig, lio_async_signal_handler);
#endif /* CRAY */
- }
+ }
#if defined(sgi)
- else if (method & LIO_WAIT_CBTYPES) {
- aiocbp.aio_sigevent.sigev_notify = SIGEV_CALLBACK;
- aiocbp.aio_sigevent.sigev_func = lio_async_callback_handler;
- /* sival_int just has to be something that I can use
- * to identify the callback, and "size" happens to be handy...
- */
- aiocbp.aio_sigevent.sigev_value.sival_int = size;
- }
+ else if (method & LIO_WAIT_CBTYPES) {
+ aiocbp.aio_sigevent.sigev_notify = SIGEV_CALLBACK;
+ aiocbp.aio_sigevent.sigev_func = lio_async_callback_handler;
+ /* sival_int just has to be something that I can use
+ * to identify the callback, and "size" happens to be handy...
+ */
+ aiocbp.aio_sigevent.sigev_value.sival_int = size;
+ }
#endif
#if defined(__linux__) && !defined(__UCLIBC__)
else if (method & LIO_WAIT_CBTYPES) {
aiocbp.aio_sigevent.sigev_notify = SIGEV_THREAD;
- aiocbp.aio_sigevent.sigev_notify_function = lio_async_callback_handler;
+ aiocbp.aio_sigevent.sigev_notify_function =
+ lio_async_callback_handler;
/* sival_int just has to be something that I can use
* to identify the callback, and "size" happens to be handy...
*/
- aiocbp.aio_sigevent.sigev_notify_attributes = (void*)(uintptr_t)size;
+ aiocbp.aio_sigevent.sigev_notify_attributes =
+ (void *)(uintptr_t) size;
}
#endif
- /*
- * Determine the system call that will be called and produce
- * the string of the system call and place it in Lio_SysCall.
- * Also update the io_type char pointer to give brief description
- * of system call. Execute the system call and check for
- * system call failure. If sync i/o, return the number of
- * bytes written/read.
- */
-
- if ((method & LIO_IO_SYNC) || (method & (LIO_IO_TYPES | LIO_IO_ATYPES)) == 0) {
/*
- * read(2) is used if LIO_IO_SYNC bit is set or not none
- * of the LIO_IO_TYPES bits are set (default).
- */
+ * Determine the system call that will be called and produce
+ * the string of the system call and place it in Lio_SysCall.
+ * Also update the io_type char pointer to give brief description
+ * of system call. Execute the system call and check for
+ * system call failure. If sync i/o, return the number of
+ * bytes written/read.
+ */
- sprintf(Lio_SysCall,
- "read(%d, buf, %d)", fd, size);
- io_type="read";
+ if ((method & LIO_IO_SYNC)
+ || (method & (LIO_IO_TYPES | LIO_IO_ATYPES)) == 0) {
+ /*
+ * read(2) is used if LIO_IO_SYNC bit is set or not none
+ * of the LIO_IO_TYPES bits are set (default).
+ */
- if (Debug_level) {
- printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__, Lio_SysCall);
- }
+ sprintf(Lio_SysCall, "read(%d, buf, %d)", fd, size);
+ io_type = "read";
- while (1) {
- if (((ret = read(fd, buffer, size)) == -1) && errno!=EINTR && errno!=EAGAIN) {
- sprintf(Errormsg, "%s/%d read(%d, buf, %d) ret:-1, errno=%d %s",
- __FILE__, __LINE__,
- fd, size, errno, strerror(errno));
- return -errno;
- }
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
- if (ret==0) return 0;
- if (ret!=-1) {
- if (ret != size) {
- sprintf(Errormsg,
- "%s/%d read(%d, buf, %d) returned=%d",
- __FILE__, __LINE__,
- fd, size, ret);
- size-=ret;
- buffer+=ret;
- }
- else {
- if (Debug_level > 1)
- printf("DEBUG %s/%d: read completed without error (ret %d)\n",
- __FILE__, __LINE__, ret);
+ while (1) {
+ if (((ret = read(fd, buffer, size)) == -1)
+ && errno != EINTR && errno != EAGAIN) {
+ sprintf(Errormsg,
+ "%s/%d read(%d, buf, %d) ret:-1, errno=%d %s",
+ __FILE__, __LINE__, fd, size, errno,
+ strerror(errno));
+ return -errno;
+ }
- return ret;
- }
- }
- wait4sync_io(fd, 1);
- }
+ if (ret == 0)
+ return 0;
+ if (ret != -1) {
+ if (ret != size) {
+ sprintf(Errormsg,
+ "%s/%d read(%d, buf, %d) returned=%d",
+ __FILE__, __LINE__,
+ fd, size, ret);
+ size -= ret;
+ buffer += ret;
+ } else {
+ if (Debug_level > 1)
+ printf
+ ("DEBUG %s/%d: read completed without error (ret %d)\n",
+ __FILE__, __LINE__, ret);
- }
+ return ret;
+ }
+ }
+ wait4sync_io(fd, 1);
+ }
- else if (method & LIO_IO_ASYNC) {
-#ifdef CRAY
- sprintf(Lio_SysCall,
- "reada(%d, buf, %d, &status, %d)", fd, size, sig);
- io_type="reada";
-
- if (Debug_level) {
- printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__, Lio_SysCall);
- }
-
- sigoff();
- if ((ret = reada(fd, buffer, size, &status, sig)) == -1) {
- sprintf(Errormsg,
- "%s/%d reada(%d, buf, %d, &stat, %d) ret:-1, errno=%d %s",
- __FILE__, __LINE__,
- fd, size, sig, errno, strerror(errno));
- sigon();
- return -errno;
}
+
+ else if (method & LIO_IO_ASYNC) {
+#ifdef CRAY
+ sprintf(Lio_SysCall,
+ "reada(%d, buf, %d, &status, %d)", fd, size, sig);
+ io_type = "reada";
+
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
+
+ sigoff();
+ if ((ret = reada(fd, buffer, size, &status, sig)) == -1) {
+ sprintf(Errormsg,
+ "%s/%d reada(%d, buf, %d, &stat, %d) ret:-1, errno=%d %s",
+ __FILE__, __LINE__,
+ fd, size, sig, errno, strerror(errno));
+ sigon();
+ return -errno;
+ }
#endif
#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
- sprintf(Lio_SysCall,
- "aio_read(fildes=%d, buf, nbytes=%d, signo=%d)", fd, size, sig);
- io_type="aio_read";
+ sprintf(Lio_SysCall,
+ "aio_read(fildes=%d, buf, nbytes=%d, signo=%d)", fd,
+ size, sig);
+ io_type = "aio_read";
- if (Debug_level) {
- printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__, Lio_SysCall);
- }
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
- if (sig)
- sighold( sig );
- if ((ret = aio_read(&aiocbp)) == -1) {
- sprintf(Errormsg,
- "%s/%d aio_read(fildes=%d, buf, nbytes=%d, signo=%d) ret:-1, errno=%d %s",
- __FILE__, __LINE__,
- fd, size, sig, errno, strerror(errno));
- if (sig)
- sigrelse( sig );
- return -errno;
+ if (sig)
+ sighold(sig);
+ if ((ret = aio_read(&aiocbp)) == -1) {
+ sprintf(Errormsg,
+ "%s/%d aio_read(fildes=%d, buf, nbytes=%d, signo=%d) ret:-1, errno=%d %s",
+ __FILE__, __LINE__,
+ fd, size, sig, errno, strerror(errno));
+ if (sig)
+ sigrelse(sig);
+ return -errno;
+ }
+#endif
}
-#endif
- } /* LIO_IO_ASYNC */
-
- else if (method & LIO_IO_SLISTIO) {
+ /* LIO_IO_ASYNC */
+ else if (method & LIO_IO_SLISTIO) {
#ifdef CRAY
- request.li_opcode = LO_READ;
- request.li_fildes = fd;
- request.li_buf = buffer;
- request.li_nbyte = size;
- request.li_status = &status;
- request.li_signo = sig;
- request.li_nstride = 0;
- request.li_filstride = 0;
- request.li_memstride = 0;
+ request.li_opcode = LO_READ;
+ request.li_fildes = fd;
+ request.li_buf = buffer;
+ request.li_nbyte = size;
+ request.li_status = &status;
+ request.li_signo = sig;
+ request.li_nstride = 0;
+ request.li_filstride = 0;
+ request.li_memstride = 0;
- listio_cmd=LC_WAIT;
- io_type="listio(2) sync read";
+ listio_cmd = LC_WAIT;
+ io_type = "listio(2) sync read";
- sprintf(Lio_SysCall,
- "listio(LC_WAIT, &req, 1) LO_READ, fd:%d, nbyte:%d",
- fd, size);
+ sprintf(Lio_SysCall,
+ "listio(LC_WAIT, &req, 1) LO_READ, fd:%d, nbyte:%d",
+ fd, size);
- if (Debug_level) {
- printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__, Lio_SysCall);
- }
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
- sigoff();
- if (listio(listio_cmd, &request, 1) == -1) {
- sprintf(Errormsg, "%s/%d %s failed, fd:%d, nbyte:%d errno=%d %s",
- __FILE__, __LINE__,
- Lio_SysCall, fd, size, errno, strerror(errno));
- sigon();
- return -errno;
- }
+ sigoff();
+ if (listio(listio_cmd, &request, 1) == -1) {
+ sprintf(Errormsg,
+ "%s/%d %s failed, fd:%d, nbyte:%d errno=%d %s",
+ __FILE__, __LINE__, Lio_SysCall, fd, size,
+ errno, strerror(errno));
+ sigon();
+ return -errno;
+ }
- if (Debug_level > 1)
- printf("DEBUG %s/%d: %s did not return -1\n",
- __FILE__, __LINE__, Lio_SysCall);
+ if (Debug_level > 1)
+ printf("DEBUG %s/%d: %s did not return -1\n",
+ __FILE__, __LINE__, Lio_SysCall);
- ret=lio_check_asyncio(io_type, size, &status);
- return ret;
+ ret = lio_check_asyncio(io_type, size, &status);
+ return ret;
#endif
#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
- aiocbp.aio_lio_opcode = LIO_READ;
- listio_cmd=LIO_WAIT;
- io_type="lio_listio(3) sync read";
+ aiocbp.aio_lio_opcode = LIO_READ;
+ listio_cmd = LIO_WAIT;
+ io_type = "lio_listio(3) sync read";
- sprintf(Lio_SysCall,
- "lio_listio(LIO_WAIT, aiolist, 1, NULL) LIO_READ, fd:%d, nbyte:%d",
- fd, size);
+ sprintf(Lio_SysCall,
+ "lio_listio(LIO_WAIT, aiolist, 1, NULL) LIO_READ, fd:%d, nbyte:%d",
+ fd, size);
- if (Debug_level) {
- printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__, Lio_SysCall);
- }
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
- if (sig)
- sighold( sig );
- if (lio_listio(listio_cmd, aiolist, 1, NULL) == -1) {
- sprintf(Errormsg, "%s/%d %s failed, fd:%d, nbyte:%d errno=%d %s",
- __FILE__, __LINE__,
- Lio_SysCall, fd, size, errno, strerror(errno));
- if (sig)
- sigrelse( sig );
- return -errno;
- }
+ if (sig)
+ sighold(sig);
+ if (lio_listio(listio_cmd, aiolist, 1, NULL) == -1) {
+ sprintf(Errormsg,
+ "%s/%d %s failed, fd:%d, nbyte:%d errno=%d %s",
+ __FILE__, __LINE__, Lio_SysCall, fd, size,
+ errno, strerror(errno));
+ if (sig)
+ sigrelse(sig);
+ return -errno;
+ }
- if (Debug_level > 1)
- printf("DEBUG %s/%d: %s did not return -1\n",
- __FILE__, __LINE__, Lio_SysCall);
+ if (Debug_level > 1)
+ printf("DEBUG %s/%d: %s did not return -1\n",
+ __FILE__, __LINE__, Lio_SysCall);
- ret=lio_check_asyncio(io_type, size, &aiocbp, method);
- return ret;
+ ret = lio_check_asyncio(io_type, size, &aiocbp, method);
+ return ret;
#endif
- }/* LIO_IO_SLISTIO */
-
- else if (method & LIO_IO_ALISTIO) {
+ }
+ /* LIO_IO_SLISTIO */
+ else if (method & LIO_IO_ALISTIO) {
#ifdef CRAY
- request.li_opcode = LO_READ;
- request.li_fildes = fd;
- request.li_buf = buffer;
- request.li_nbyte = size;
- request.li_status = &status;
- request.li_signo = sig;
- request.li_nstride = 0;
- request.li_filstride = 0;
- request.li_memstride = 0;
+ request.li_opcode = LO_READ;
+ request.li_fildes = fd;
+ request.li_buf = buffer;
+ request.li_nbyte = size;
+ request.li_status = &status;
+ request.li_signo = sig;
+ request.li_nstride = 0;
+ request.li_filstride = 0;
+ request.li_memstride = 0;
- listio_cmd=LC_START;
- io_type="listio(2) async read";
+ listio_cmd = LC_START;
+ io_type = "listio(2) async read";
- sprintf(Lio_SysCall,
- "listio(LC_START, &req, 1) LO_READ, fd:%d, nbyte:%d",
- fd, size);
+ sprintf(Lio_SysCall,
+ "listio(LC_START, &req, 1) LO_READ, fd:%d, nbyte:%d",
+ fd, size);
- if (Debug_level) {
- printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__, Lio_SysCall);
- }
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
- sigoff();
- if (listio(listio_cmd, &request, 1) == -1) {
- sprintf(Errormsg, "%s/%d %s failed, fd:%d, nbyte:%d errno=%d %s",
- __FILE__, __LINE__,
- Lio_SysCall, fd, size, errno, strerror(errno));
- sigon();
- return -errno;
- }
+ sigoff();
+ if (listio(listio_cmd, &request, 1) == -1) {
+ sprintf(Errormsg,
+ "%s/%d %s failed, fd:%d, nbyte:%d errno=%d %s",
+ __FILE__, __LINE__, Lio_SysCall, fd, size,
+ errno, strerror(errno));
+ sigon();
+ return -errno;
+ }
#endif
#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
- aiocbp.aio_lio_opcode = LIO_READ;
- listio_cmd=LIO_NOWAIT;
- io_type="lio_listio(3) async read";
+ aiocbp.aio_lio_opcode = LIO_READ;
+ listio_cmd = LIO_NOWAIT;
+ io_type = "lio_listio(3) async read";
- sprintf(Lio_SysCall,
- "lio_listio(LIO_NOWAIT, aiolist, 1, NULL) LIO_READ, fd:%d, nbyte:%d",
- fd, size);
+ sprintf(Lio_SysCall,
+ "lio_listio(LIO_NOWAIT, aiolist, 1, NULL) LIO_READ, fd:%d, nbyte:%d",
+ fd, size);
- if (Debug_level) {
- printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__, Lio_SysCall);
- }
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
- if (sig)
- sighold( sig );
- if (lio_listio(listio_cmd, aiolist, 1, NULL) == -1) {
- sprintf(Errormsg, "%s/%d %s failed, fd:%d, nbyte:%d errno=%d %s",
- __FILE__, __LINE__,
- Lio_SysCall, fd, size, errno, strerror(errno));
- if (sig)
- sigrelse( sig );
- return -errno;
- }
+ if (sig)
+ sighold(sig);
+ if (lio_listio(listio_cmd, aiolist, 1, NULL) == -1) {
+ sprintf(Errormsg,
+ "%s/%d %s failed, fd:%d, nbyte:%d errno=%d %s",
+ __FILE__, __LINE__, Lio_SysCall, fd, size,
+ errno, strerror(errno));
+ if (sig)
+ sigrelse(sig);
+ return -errno;
+ }
#endif
- } /* LIO_IO_ALISTIO */
-
+ }
+ /* LIO_IO_ALISTIO */
#ifndef CRAY
- else if (method & LIO_IO_SYNCV) {
- io_type="readv(2)";
+ else if (method & LIO_IO_SYNCV) {
+ io_type = "readv(2)";
- sprintf(Lio_SysCall,
- "readv(%d, &iov, 1) nbyte:%d", fd, size);
+ sprintf(Lio_SysCall, "readv(%d, &iov, 1) nbyte:%d", fd, size);
- if (Debug_level) {
- printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__, Lio_SysCall);
- }
- if ((ret = readv(fd, &iov, 1)) == -1) {
- sprintf(Errormsg, "%s/%d readv(%d, iov, 1) nbyte:%d ret:-1, errno=%d %s",
- __FILE__, __LINE__,
- fd, size, errno, strerror(errno));
- return -errno;
- }
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
+ if ((ret = readv(fd, &iov, 1)) == -1) {
+ sprintf(Errormsg,
+ "%s/%d readv(%d, iov, 1) nbyte:%d ret:-1, errno=%d %s",
+ __FILE__, __LINE__, fd, size, errno,
+ strerror(errno));
+ return -errno;
+ }
- if (ret != size) {
- sprintf(Errormsg,
- "%s/%d readv(%d, iov, 1) nbyte:%d returned=%d",
- __FILE__, __LINE__,
- fd, size, ret);
- }
- else if (Debug_level > 1)
- printf("DEBUG %s/%d: readv completed without error (ret %d)\n",
- __FILE__, __LINE__, ret);
+ if (ret != size) {
+ sprintf(Errormsg,
+ "%s/%d readv(%d, iov, 1) nbyte:%d returned=%d",
+ __FILE__, __LINE__, fd, size, ret);
+ } else if (Debug_level > 1)
+ printf
+ ("DEBUG %s/%d: readv completed without error (ret %d)\n",
+ __FILE__, __LINE__, ret);
- return ret;
- } /* LIO_IO_SYNCV */
+ return ret;
+ } /* LIO_IO_SYNCV */
#endif
#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
- else if (method & LIO_IO_SYNCP) {
- io_type="pread(2)";
+ else if (method & LIO_IO_SYNCP) {
+ io_type = "pread(2)";
- sprintf(Lio_SysCall,
- "pread(%d, buf, %d, %lld)", fd, size, (long long)poffset);
+ sprintf(Lio_SysCall,
+ "pread(%d, buf, %d, %lld)", fd, size,
+ (long long)poffset);
- if (Debug_level) {
- printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__, Lio_SysCall);
- }
- if ((ret = pread(fd, buffer, size, poffset)) == -1) {
- sprintf(Errormsg, "%s/%d pread(%d, buf, %d, %lld) ret:-1, errno=%d %s",
- __FILE__, __LINE__,
- fd, size, (long long)poffset, errno, strerror(errno));
- return -errno;
- }
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
+ if ((ret = pread(fd, buffer, size, poffset)) == -1) {
+ sprintf(Errormsg,
+ "%s/%d pread(%d, buf, %d, %lld) ret:-1, errno=%d %s",
+ __FILE__, __LINE__, fd, size,
+ (long long)poffset, errno, strerror(errno));
+ return -errno;
+ }
- if (ret != size) {
- sprintf(Errormsg,
- "%s/%d pread(%d, buf, %d, %lld) returned=%d",
- __FILE__, __LINE__,
- fd, size, (long long)poffset, ret);
- }
- else if (Debug_level > 1)
- printf("DEBUG %s/%d: pread completed without error (ret %d)\n",
- __FILE__, __LINE__, ret);
+ if (ret != size) {
+ sprintf(Errormsg,
+ "%s/%d pread(%d, buf, %d, %lld) returned=%d",
+ __FILE__, __LINE__,
+ fd, size, (long long)poffset, ret);
+ } else if (Debug_level > 1)
+ printf
+ ("DEBUG %s/%d: pread completed without error (ret %d)\n",
+ __FILE__, __LINE__, ret);
- return ret;
- } /* LIO_IO_SYNCP */
+ return ret;
+ } /* LIO_IO_SYNCP */
#endif
- else {
- printf("DEBUG %s/%d: No I/O method chosen\n", __FILE__, __LINE__ );
- return -1;
- }
+ else {
+ printf("DEBUG %s/%d: No I/O method chosen\n", __FILE__,
+ __LINE__);
+ return -1;
+ }
- /*
- * wait for async io to complete.
- * Note: Sync io should have returned prior to getting here.
- */
+ /*
+ * wait for async io to complete.
+ * Note: Sync io should have returned prior to getting here.
+ */
#ifdef CRAY
- ret=lio_wait4asyncio(method, fd, statptr);
+ ret = lio_wait4asyncio(method, fd, statptr);
#endif
#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
- ret=lio_wait4asyncio(method, fd, &aiocbp);
+ ret = lio_wait4asyncio(method, fd, &aiocbp);
#endif
- /*
- * If there was an error waiting for async i/o to complete,
- * return the error value (errno) to the caller.
- * Note: Errormsg should already have been updated.
- */
- if (ret < 0) {
+ /*
+ * If there was an error waiting for async i/o to complete,
+ * return the error value (errno) to the caller.
+ * Note: Errormsg should already have been updated.
+ */
+ if (ret < 0) {
+ return ret;
+ }
+
+ /*
+ * If i/o was not waited for (may not have been completed at this time),
+ * return the size that was requested.
+ */
+ if (ret == 1)
+ return size;
+
+ /*
+ * check that async io was successful.
+ * Note: if the there was an system call failure, -errno
+ * was returned and Errormsg should already have been updated.
+ * If amount i/o was different than size, Errormsg should already
+ * have been updated but the actual i/o size if returned.
+ */
+
+#ifdef CRAY
+ ret = lio_check_asyncio(io_type, size, &status);
+#endif
+#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+ ret = lio_check_asyncio(io_type, size, &aiocbp, method);
+#endif
+
return ret;
- }
-
- /*
- * If i/o was not waited for (may not have been completed at this time),
- * return the size that was requested.
- */
- if (ret == 1)
- return size;
-
- /*
- * check that async io was successful.
- * Note: if the there was an system call failure, -errno
- * was returned and Errormsg should already have been updated.
- * If amount i/o was different than size, Errormsg should already
- * have been updated but the actual i/o size if returned.
- */
-
-#ifdef CRAY
- ret=lio_check_asyncio(io_type, size, &status);
-#endif
-#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
- ret=lio_check_asyncio(io_type, size, &aiocbp, method);
-#endif
-
- return ret;
-} /* end of lio_read_buffer */
-
+} /* end of lio_read_buffer */
#if !defined(__sun) && !defined(__hpux) && !defined(_AIX)
/***********************************************************************
@@ -1612,100 +1660,100 @@
#ifdef CRAY
int lio_check_asyncio(char *io_type, int size, struct iosw *status)
#elif defined(sgi)
- int lio_check_asyncio(char *io_type, int size, aiocb_t *aiocbp, int method)
+int lio_check_asyncio(char *io_type, int size, aiocb_t * aiocbp, int method)
#elif defined(__linux__) && !defined(__UCLIBC__)
- int lio_check_asyncio(char *io_type, int size, struct aiocb *aiocbp, int method)
+int lio_check_asyncio(char *io_type, int size, struct aiocb *aiocbp, int method)
{
- int ret;
+ int ret;
#ifdef CRAY
- if (status->sw_error) {
- sprintf(Errormsg,
- "%s/%d %s, sw_error set = %d %s, sw_count = %d",
- __FILE__, __LINE__, io_type,
- status->sw_error, strerror(status->sw_error), status->sw_count);
- return -status->sw_error;
- }
- else if (status->sw_count != size) {
- sprintf(Errormsg,
- "%s/%d %s, sw_count not as expected(%d), but actual:%d",
- __FILE__, __LINE__, io_type,
- size, status->sw_count);
- }
- else if (Debug_level > 1) {
- printf("DEBUG %s/%d: %s completed without error (sw_error == 0, sw_count == %d)\n",
- __FILE__, __LINE__, io_type, status->sw_count);
- }
+ if (status->sw_error) {
+ sprintf(Errormsg,
+ "%s/%d %s, sw_error set = %d %s, sw_count = %d",
+ __FILE__, __LINE__, io_type,
+ status->sw_error, strerror(status->sw_error),
+ status->sw_count);
+ return -status->sw_error;
+ } else if (status->sw_count != size) {
+ sprintf(Errormsg,
+ "%s/%d %s, sw_count not as expected(%d), but actual:%d",
+ __FILE__, __LINE__, io_type, size, status->sw_count);
+ } else if (Debug_level > 1) {
+ printf
+ ("DEBUG %s/%d: %s completed without error (sw_error == 0, sw_count == %d)\n",
+ __FILE__, __LINE__, io_type, status->sw_count);
+ }
- return status->sw_count;
+ return status->sw_count;
#else
- int cnt = 1;
+ int cnt = 1;
- /* The I/O may have been synchronous with signal completion. It doesn't
- * make sense, but the combination could be generated. Release the
- * completion signal here otherwise it'll hang around and bite us
- * later.
- */
- if (aiocbp->aio_sigevent.sigev_notify == SIGEV_SIGNAL)
- sigrelse( aiocbp->aio_sigevent.sigev_signo );
+ /* The I/O may have been synchronous with signal completion. It doesn't
+ * make sense, but the combination could be generated. Release the
+ * completion signal here otherwise it'll hang around and bite us
+ * later.
+ */
+ if (aiocbp->aio_sigevent.sigev_notify == SIGEV_SIGNAL)
+ sigrelse(aiocbp->aio_sigevent.sigev_signo);
- ret = aio_error( aiocbp );
+ ret = aio_error(aiocbp);
- while (ret == EINPROGRESS) {
- ret = aio_error( aiocbp );
- ++cnt;
- }
- if (cnt > 1) {
- sprintf(Errormsg,
- "%s/%d %s, aio_error had to loop on EINPROGRESS, cnt=%d; random method %#o; sigev_notify=%s",
- __FILE__, __LINE__, io_type, cnt, method,
- (aiocbp->aio_sigevent.sigev_notify == SIGEV_SIGNAL ? "signal" :
- aiocbp->aio_sigevent.sigev_notify == SIGEV_NONE ? "none" :
+ while (ret == EINPROGRESS) {
+ ret = aio_error(aiocbp);
+ ++cnt;
+ }
+ if (cnt > 1) {
+ sprintf(Errormsg,
+ "%s/%d %s, aio_error had to loop on EINPROGRESS, cnt=%d; random method %#o; sigev_notify=%s",
+ __FILE__, __LINE__, io_type, cnt, method,
+ (aiocbp->aio_sigevent.sigev_notify ==
+ SIGEV_SIGNAL ? "signal" : aiocbp->aio_sigevent.
+ sigev_notify == SIGEV_NONE ? "none" :
#ifdef SIGEV_CALLBACK
- aiocbp->aio_sigevent.sigev_notify == SIGEV_CALLBACK ? "callback" :
+ aiocbp->aio_sigevent.sigev_notify ==
+ SIGEV_CALLBACK ? "callback" :
#endif
- aiocbp->aio_sigevent.sigev_notify == SIGEV_THREAD ? "thread" :
- "unknown") );
- return -ret;
- }
+ aiocbp->aio_sigevent.sigev_notify ==
+ SIGEV_THREAD ? "thread" : "unknown"));
+ return -ret;
+ }
- if (ret != 0) {
- sprintf(Errormsg,
- "%s/%d %s, aio_error = %d %s; random method %#o",
- __FILE__, __LINE__, io_type,
- ret, strerror(ret),
- method );
- return -ret;
- }
- ret = aio_return( aiocbp );
- if (ret != size) {
- sprintf(Errormsg,
- "%s/%d %s, aio_return not as expected(%d), but actual:%d",
- __FILE__, __LINE__, io_type,
- size, ret);
+ if (ret != 0) {
+ sprintf(Errormsg,
+ "%s/%d %s, aio_error = %d %s; random method %#o",
+ __FILE__, __LINE__, io_type,
+ ret, strerror(ret), method);
+ return -ret;
+ }
+ ret = aio_return(aiocbp);
+ if (ret != size) {
+ sprintf(Errormsg,
+ "%s/%d %s, aio_return not as expected(%d), but actual:%d",
+ __FILE__, __LINE__, io_type, size, ret);
#ifdef BUG1_workaround
- if (ret == 0) {
- ret = size;
- if (Debug_level > 1) {
- printf("WARN %s/%d: %s completed with bug1_workaround (aio_error == 0, aio_return now == %d)\n",
- __FILE__, __LINE__, io_type, ret);
+ if (ret == 0) {
+ ret = size;
+ if (Debug_level > 1) {
+ printf
+ ("WARN %s/%d: %s completed with bug1_workaround (aio_error == 0, aio_return now == %d)\n",
+ __FILE__, __LINE__, io_type, ret);
+ }
}
- }
#endif /* BUG1_workaround */
- }
- else if (Debug_level > 1) {
- printf("DEBUG %s/%d: %s completed without error (aio_error == 0, aio_return == %d)\n",
- __FILE__, __LINE__, io_type, ret);
- }
+ } else if (Debug_level > 1) {
+ printf
+ ("DEBUG %s/%d: %s completed without error (aio_error == 0, aio_return == %d)\n",
+ __FILE__, __LINE__, io_type, ret);
+ }
- return ret;
+ return ret;
#endif
-} /* end of lio_check_asyncio */
+} /* end of lio_check_asyncio */
#endif
/***********************************************************************
@@ -1729,175 +1777,189 @@
#ifdef CRAY
int lio_wait4asyncio(int method, int fd, struct iosw **statptr)
#elif defined(sgi)
- int lio_wait4asyncio(int method, int fd, aiocb_t *aiocbp)
+int lio_wait4asyncio(int method, int fd, aiocb_t * aiocbp)
#elif defined(__linux__) && !defined(__UCLIBC__)
- int lio_wait4asyncio(int method, int fd, struct aiocb *aiocbp)
+int lio_wait4asyncio(int method, int fd, struct aiocb *aiocbp)
{
- int cnt;
+ int cnt;
#ifdef sgi
- int ret;
- const aiocb_t *aioary[1];
+ int ret;
+ const aiocb_t *aioary[1];
#endif
#if defined(__linux__)&& !defined(__UCLIBC__)
int ret;
const struct aiocb *aioary[1];
#endif
- if ((method & LIO_WAIT_RECALL)
+ if ((method & LIO_WAIT_RECALL)
#if defined(sgi) || (defined(__linux__)&& !defined(__UCLIBC__))
- || (method & LIO_WAIT_CBSUSPEND)
- || (method & LIO_WAIT_SIGSUSPEND)
+ || (method & LIO_WAIT_CBSUSPEND)
+ || (method & LIO_WAIT_SIGSUSPEND)
#endif
- || ((method & LIO_WAIT_TYPES) == 0) ) {
- /*
- * If method has LIO_WAIT_RECALL bit set or method does
- * not have any wait method bits set (default), use recall/aio_suspend.
- */
+ || ((method & LIO_WAIT_TYPES) == 0)) {
+ /*
+ * If method has LIO_WAIT_RECALL bit set or method does
+ * not have any wait method bits set (default), use recall/aio_suspend.
+ */
#ifdef CRAY
- if (Debug_level > 2)
- printf("DEBUG %s/%d: wait method : recall\n", __FILE__, __LINE__);
- sigon();
- if (recall(fd, 1, statptr)) {
- sprintf(Errormsg, "%s/%d recall(%d, 1, stat) failed, errno:%d %s",
- __FILE__, __LINE__,
- fd, errno, strerror(errno));
- return -errno;
- }
-#else
- if (Debug_level > 2)
- printf("DEBUG %s/%d: wait method : aio_suspend, sigev_notify=%s\n", __FILE__, __LINE__,
- (aiocbp->aio_sigevent.sigev_notify == SIGEV_SIGNAL ? "signal" :
- aiocbp->aio_sigevent.sigev_notify == SIGEV_NONE ? "none" :
-#ifdef SIGEV_CALLBACK
- aiocbp->aio_sigevent.sigev_notify == SIGEV_CALLBACK ? "callback" :
-#endif
- aiocbp->aio_sigevent.sigev_notify == SIGEV_THREAD ? "thread" :
- "unknown") );
-
- aioary[0] = aiocbp;
- ret = aio_suspend( aioary, 1, NULL );
- if ((ret == -1) && (errno == EINTR)) {
- if (aiocbp->aio_sigevent.sigev_notify == SIGEV_SIGNAL) {
- if (Debug_level > 2) {
- printf("DEBUG %s/%d: aio_suspend received EINTR, sigev_notify=SIGEV_SIGNAL -- ok\n",
- __FILE__, __LINE__ );
- }
- }
- else {
- sprintf(Errormsg, "%s/%d aio_suspend received EINTR, sigev_notify=%s, not ok\n",
- __FILE__, __LINE__,
- (aiocbp->aio_sigevent.sigev_notify == SIGEV_SIGNAL ? "signal" :
- aiocbp->aio_sigevent.sigev_notify == SIGEV_NONE ? "none" :
-#ifdef SIGEV_CALLBACK
- aiocbp->aio_sigevent.sigev_notify == SIGEV_CALLBACK ? "callback" :
-#endif
- aiocbp->aio_sigevent.sigev_notify == SIGEV_THREAD ? "thread" :
- "unknown") );
+ if (Debug_level > 2)
+ printf("DEBUG %s/%d: wait method : recall\n", __FILE__,
+ __LINE__);
+ sigon();
+ if (recall(fd, 1, statptr)) {
+ sprintf(Errormsg,
+ "%s/%d recall(%d, 1, stat) failed, errno:%d %s",
+ __FILE__, __LINE__, fd, errno, strerror(errno));
return -errno;
}
- }
- else if (ret) {
- sprintf(Errormsg, "%s/%d aio_suspend(fildes=%d, aioary, 1, NULL) failed, errno:%d %s",
- __FILE__, __LINE__,
- fd, errno, strerror(errno));
- return -errno;
- }
-#endif
-
- } else if (method & LIO_WAIT_ACTIVE) {
- if (Debug_level > 2)
- printf("DEBUG %s/%d: wait method : active\n", __FILE__, __LINE__);
-#ifdef CRAY
- sigon();
- /*
- * loop until sw_flag, sw_count or sw_error field elements
- * change to non-zero.
- */
- cnt=0;
- while ((*statptr)->sw_flag == 0 &&
- (*statptr)->sw_count == 0 &&
- (*statptr)->sw_error == 0 ) {
- cnt++;
- }
#else
- /* loop while aio_error() returns EINPROGRESS */
- cnt=0;
- while (1) {
- ret = aio_error( aiocbp );
- if ((ret == 0) || (ret != EINPROGRESS)) {
- break;
+ if (Debug_level > 2)
+ printf
+ ("DEBUG %s/%d: wait method : aio_suspend, sigev_notify=%s\n",
+ __FILE__, __LINE__,
+ (aiocbp->aio_sigevent.sigev_notify ==
+ SIGEV_SIGNAL ? "signal" : aiocbp->aio_sigevent.
+ sigev_notify == SIGEV_NONE ? "none" :
+#ifdef SIGEV_CALLBACK
+ aiocbp->aio_sigevent.sigev_notify ==
+ SIGEV_CALLBACK ? "callback" :
+#endif
+ aiocbp->aio_sigevent.sigev_notify ==
+ SIGEV_THREAD ? "thread" : "unknown"));
+
+ aioary[0] = aiocbp;
+ ret = aio_suspend(aioary, 1, NULL);
+ if ((ret == -1) && (errno == EINTR)) {
+ if (aiocbp->aio_sigevent.sigev_notify == SIGEV_SIGNAL) {
+ if (Debug_level > 2) {
+ printf
+ ("DEBUG %s/%d: aio_suspend received EINTR, sigev_notify=SIGEV_SIGNAL -- ok\n",
+ __FILE__, __LINE__);
+ }
+ } else {
+ sprintf(Errormsg,
+ "%s/%d aio_suspend received EINTR, sigev_notify=%s, not ok\n",
+ __FILE__, __LINE__,
+ (aiocbp->aio_sigevent.sigev_notify ==
+ SIGEV_SIGNAL ? "signal" : aiocbp->
+ aio_sigevent.sigev_notify ==
+ SIGEV_NONE ? "none" :
+#ifdef SIGEV_CALLBACK
+ aiocbp->aio_sigevent.sigev_notify ==
+ SIGEV_CALLBACK ? "callback" :
+#endif
+ aiocbp->aio_sigevent.sigev_notify ==
+ SIGEV_THREAD ? "thread" : "unknown"));
+ return -errno;
+ }
+ } else if (ret) {
+ sprintf(Errormsg,
+ "%s/%d aio_suspend(fildes=%d, aioary, 1, NULL) failed, errno:%d %s",
+ __FILE__, __LINE__, fd, errno, strerror(errno));
+ return -errno;
}
- ++cnt;
- }
+#endif
+
+ } else if (method & LIO_WAIT_ACTIVE) {
+ if (Debug_level > 2)
+ printf("DEBUG %s/%d: wait method : active\n", __FILE__,
+ __LINE__);
+#ifdef CRAY
+ sigon();
+ /*
+ * loop until sw_flag, sw_count or sw_error field elements
+ * change to non-zero.
+ */
+ cnt = 0;
+ while ((*statptr)->sw_flag == 0 &&
+ (*statptr)->sw_count == 0 && (*statptr)->sw_error == 0) {
+ cnt++;
+ }
+#else
+ /* loop while aio_error() returns EINPROGRESS */
+ cnt = 0;
+ while (1) {
+ ret = aio_error(aiocbp);
+ if ((ret == 0) || (ret != EINPROGRESS)) {
+ break;
+ }
+ ++cnt;
+ }
#endif
- if (Debug_level > 5 && cnt && (cnt % 50) == 0)
- printf("DEBUG %s/%d: wait active cnt = %d\n",
- __FILE__, __LINE__, cnt);
+ if (Debug_level > 5 && cnt && (cnt % 50) == 0)
+ printf("DEBUG %s/%d: wait active cnt = %d\n",
+ __FILE__, __LINE__, cnt);
- } else if (method & LIO_WAIT_SIGPAUSE) {
- if (Debug_level > 2)
- printf("DEBUG %s/%d: wait method : sigpause\n", __FILE__, __LINE__);
+ } else if (method & LIO_WAIT_SIGPAUSE) {
+ if (Debug_level > 2)
+ printf("DEBUG %s/%d: wait method : sigpause\n",
+ __FILE__, __LINE__);
#ifdef sgi
- /* note: don't do the sigon() for CRAY in this case. why? -- roehrich 6/11/97 */
- if (aiocbp->aio_sigevent.sigev_notify == SIGEV_SIGNAL)
- sigrelse( aiocbp->aio_sigevent.sigev_signo );
- else {
- printf("DEBUG %s/%d: sigev_notify != SIGEV_SIGNAL\n", __FILE__, __LINE__ );
- return -1;
- }
+ /* note: don't do the sigon() for CRAY in this case. why? -- roehrich 6/11/97 */
+ if (aiocbp->aio_sigevent.sigev_notify == SIGEV_SIGNAL)
+ sigrelse(aiocbp->aio_sigevent.sigev_signo);
+ else {
+ printf("DEBUG %s/%d: sigev_notify != SIGEV_SIGNAL\n",
+ __FILE__, __LINE__);
+ return -1;
+ }
#endif
- pause();
+ pause();
- } else if (method & LIO_WAIT_SIGACTIVE) {
- if (Debug_level > 2)
- printf("DEBUG %s/%d: wait method : sigactive\n", __FILE__, __LINE__);
+ } else if (method & LIO_WAIT_SIGACTIVE) {
+ if (Debug_level > 2)
+ printf("DEBUG %s/%d: wait method : sigactive\n",
+ __FILE__, __LINE__);
#ifdef CRAY
- sigon();
+ sigon();
#else
- if (aiocbp->aio_sigevent.sigev_notify == SIGEV_SIGNAL)
- sigrelse( aiocbp->aio_sigevent.sigev_signo );
- else {
- printf("DEBUG %s/%d: sigev_notify != SIGEV_SIGNAL\n", __FILE__, __LINE__ );
- return -1;
- }
+ if (aiocbp->aio_sigevent.sigev_notify == SIGEV_SIGNAL)
+ sigrelse(aiocbp->aio_sigevent.sigev_signo);
+ else {
+ printf("DEBUG %s/%d: sigev_notify != SIGEV_SIGNAL\n",
+ __FILE__, __LINE__);
+ return -1;
+ }
#endif
- /* loop waiting for signal */
- while (Received_signal == Rec_signal) {
+ /* loop waiting for signal */
+ while (Received_signal == Rec_signal) {
#ifdef CRAY
- sigon();
+ sigon();
#else
- sigrelse( aiocbp->aio_sigevent.sigev_signo );
+ sigrelse(aiocbp->aio_sigevent.sigev_signo);
#endif
- }
+ }
- } else if (method & LIO_WAIT_NONE) {
- if (Debug_level > 2)
- printf("DEBUG %s/%d: wait method : none\n", __FILE__, __LINE__);
- /* It's broken because the aiocb/iosw is an automatic variable in
- * lio_{read,write}_buffer, so when the function returns and the
- * I/O completes there will be nowhere to write the I/O status.
- * It doesn't cause a problem on unicos--probably because of some
- * compiler quirk, or an accident. It causes POSIX async I/O
- * to core dump some threads. spr/pv 705909. 6/27/97 roehrich
- */
- sprintf(Errormsg, "%s/%d LIO_WAIT_NONE was selected (this is broken)\n",
- __FILE__, __LINE__ );
+ } else if (method & LIO_WAIT_NONE) {
+ if (Debug_level > 2)
+ printf("DEBUG %s/%d: wait method : none\n", __FILE__,
+ __LINE__);
+ /* It's broken because the aiocb/iosw is an automatic variable in
+ * lio_{read,write}_buffer, so when the function returns and the
+ * I/O completes there will be nowhere to write the I/O status.
+ * It doesn't cause a problem on unicos--probably because of some
+ * compiler quirk, or an accident. It causes POSIX async I/O
+ * to core dump some threads. spr/pv 705909. 6/27/97 roehrich
+ */
+ sprintf(Errormsg,
+ "%s/%d LIO_WAIT_NONE was selected (this is broken)\n",
+ __FILE__, __LINE__);
#ifdef CRAY
- sigon();
+ sigon();
#endif
/* return 1;*/
- return -1;
- }
- else {
- if (Debug_level > 2)
- printf("DEBUG %s/%d: no wait method was chosen\n", __FILE__, __LINE__ );
- return -1;
- }
+ return -1;
+ } else {
+ if (Debug_level > 2)
+ printf("DEBUG %s/%d: no wait method was chosen\n",
+ __FILE__, __LINE__);
+ return -1;
+ }
- return 0;
+ return 0;
-} /* end of lio_wait4asyncio */
+} /* end of lio_wait4asyncio */
#endif /* ifndef linux */
#endif
@@ -1910,175 +1972,201 @@
* (rrl 04/96)
***********************************************************************/
struct unit_info_t {
- int method;
- int sig;
- char *str;
-} Unit_info[] = {
- { LIO_IO_SYNC, 0, "sync io" },
- { LIO_IO_SYNCV, 0, "sync readv/writev" },
- { LIO_IO_SYNCP, 0, "sync pread/pwrite" },
- { LIO_IO_ASYNC, 0, "async io, def wait" },
- { LIO_IO_SLISTIO, 0, "sync listio" },
- { LIO_IO_ALISTIO, 0, "async listio, def wait" },
- { LIO_IO_ASYNC|LIO_WAIT_ACTIVE, 0, "async active" },
- { LIO_IO_ASYNC|LIO_WAIT_RECALL, 0, "async recall/suspend" },
- { LIO_IO_ASYNC|LIO_WAIT_SIGPAUSE, SIGUSR1, "async sigpause" },
- { LIO_IO_ASYNC|LIO_WAIT_SIGACTIVE, SIGUSR1, "async sigactive" },
- { LIO_IO_ALISTIO|LIO_WAIT_ACTIVE, 0, "async listio active" },
- { LIO_IO_ALISTIO|LIO_WAIT_RECALL, 0, "async listio recall" },
- { LIO_IO_ALISTIO|LIO_WAIT_SIGACTIVE, SIGUSR1, "async listio sigactive" },
- { LIO_IO_ALISTIO|LIO_WAIT_SIGPAUSE, SIGUSR1, "async listio sigpause" },
- { LIO_IO_ASYNC, SIGUSR2, "async io, def wait, sigusr2" },
- { LIO_IO_ALISTIO, SIGUSR2, "async listio, def wait, sigusr2" },
-};
+ int method;
+ int sig;
+ char *str;
+} Unit_info[] = {
+ {
+ LIO_IO_SYNC, 0, "sync io"}, {
+ LIO_IO_SYNCV, 0, "sync readv/writev"}, {
+ LIO_IO_SYNCP, 0, "sync pread/pwrite"}, {
+ LIO_IO_ASYNC, 0, "async io, def wait"}, {
+ LIO_IO_SLISTIO, 0, "sync listio"}, {
+ LIO_IO_ALISTIO, 0, "async listio, def wait"}, {
+ LIO_IO_ASYNC | LIO_WAIT_ACTIVE, 0, "async active"}, {
+ LIO_IO_ASYNC | LIO_WAIT_RECALL, 0, "async recall/suspend"}, {
+ LIO_IO_ASYNC | LIO_WAIT_SIGPAUSE, SIGUSR1, "async sigpause"}, {
+ LIO_IO_ASYNC | LIO_WAIT_SIGACTIVE, SIGUSR1, "async sigactive"}, {
+ LIO_IO_ALISTIO | LIO_WAIT_ACTIVE, 0, "async listio active"}, {
+ LIO_IO_ALISTIO | LIO_WAIT_RECALL, 0, "async listio recall"}, {
+ LIO_IO_ALISTIO | LIO_WAIT_SIGACTIVE, SIGUSR1, "async listio sigactive"},
+ {
+ LIO_IO_ALISTIO | LIO_WAIT_SIGPAUSE, SIGUSR1, "async listio sigpause"},
+ {
+ LIO_IO_ASYNC, SIGUSR2, "async io, def wait, sigusr2"}, {
+LIO_IO_ALISTIO, SIGUSR2, "async listio, def wait, sigusr2"},};
-int
-main(argc, argv)
+int main(argc, argv)
int argc;
char **argv;
{
- extern char *optarg;
- extern int optind;
+ extern char *optarg;
+ extern int optind;
- int fd;
- char *err;
- char buffer[4096];
- int size=4096;
- int ret;
- int ind;
- int iter=3;
- int method;
- int exit_status = 0;
- int c;
- int i;
- char *symbols = NULL;
- int die_on_err = 0;
+ int fd;
+ char *err;
+ char buffer[4096];
+ int size = 4096;
+ int ret;
+ int ind;
+ int iter = 3;
+ int method;
+ int exit_status = 0;
+ int c;
+ int i;
+ char *symbols = NULL;
+ int die_on_err = 0;
- while ((c = getopt(argc,argv,"s:di:")) != -1) {
- switch(c) {
- case 's': symbols = optarg; break;
- case 'd': ++die_on_err; break;
- case 'i': iter = atoi(optarg); break;
- }
- }
-
- if ((fd=open("unit_test_file", O_CREAT|O_RDWR|O_TRUNC, 0777)) == -1) {
- perror("open(unit_test_file, O_CREAT|O_RDWR|O_TRUNC, 0777) failed");
- exit(1);
- }
-
- Debug_level=9;
-
- if (symbols != NULL) {
- if ((method=lio_parse_io_arg2(symbols, &err)) == -1) {
- printf("lio_parse_io_arg2(%s, &err) failed, bad token starting at %s\n",
- symbols, err);
- if (die_on_err)
- exit(1);
- }
- else
- printf("lio_parse_io_arg2(%s, &err) returned %#o\n", symbols, method);
-
- exit_status = 0;
- for (ind=0; ind < iter; ind++) {
- memset( buffer, 'A', 4096 );
- if (lseek(fd, 0, 0) == -1) {
- printf("lseek(fd,0,0), %d, failed, errno %d\n",
- __LINE__, errno );
- ++exit_status;
- }
- if ((ret=lio_write_buffer(fd, method, buffer,
- size, SIGUSR1, &err, 0)) != size ) {
- printf("lio_write_buffer returned -1, err = %s\n", err);
- } else
- printf("lio_write_buffer returned %d\n", ret);
-
- memset( buffer, 'B', 4096 );
- if (lseek(fd, 0, 0) == -1) {
- printf("lseek(fd,0,0), %d, failed, errno %d\n",
- __LINE__, errno );
- ++exit_status;
- }
- if ((ret=lio_read_buffer(fd, method, buffer,
- size, SIGUSR2, &err, 0)) != size ) {
- printf("lio_read_buffer returned -1, err = %s\n", err);
- } else
- printf("lio_read_buffer returned %d\n", ret);
-
- for (i = 0; i < 4096; ++i) {
- if (buffer[i] != 'A') {
- printf(" buffer[%d] = %d\n", i, buffer[i] );
- ++exit_status;
+ while ((c = getopt(argc, argv, "s:di:")) != -1) {
+ switch (c) {
+ case 's':
+ symbols = optarg;
+ break;
+ case 'd':
+ ++die_on_err;
+ break;
+ case 'i':
+ iter = atoi(optarg);
break;
}
- }
-
- if (exit_status)
- exit(exit_status);
-
}
- unlink("unit_test_file");
- exit(0);
- }
-
- for (ind=0; ind < sizeof(Unit_info)/sizeof(struct unit_info_t); ind++) {
-
- printf("\n********* write %s ***************\n", Unit_info[ind].str);
- if (lseek(fd, 0, 0) == -1) {
- printf("lseek(fd,0,0), %d, failed, errno %d\n",
- __LINE__, errno );
- ++exit_status;
+ if ((fd =
+ open("unit_test_file", O_CREAT | O_RDWR | O_TRUNC, 0777)) == -1) {
+ perror
+ ("open(unit_test_file, O_CREAT|O_RDWR|O_TRUNC, 0777) failed");
+ exit(1);
}
- memset( buffer, 'A', 4096 );
- if ((ret=lio_write_buffer(fd, Unit_info[ind].method, buffer,
- size, Unit_info[ind].sig, &err, 0)) != size ) {
- printf(">>>>> lio_write_buffer(fd,0%x,buffer,%d,%d,err,0) returned -1,\n err = %s\n",
- Unit_info[ind].method, size, Unit_info[ind].sig, err);
- ++exit_status;
- if (die_on_err)
- exit(exit_status);
- } else{
- printf("lio_write_buffer returned %d\n", ret);
+ Debug_level = 9;
+
+ if (symbols != NULL) {
+ if ((method = lio_parse_io_arg2(symbols, &err)) == -1) {
+ printf
+ ("lio_parse_io_arg2(%s, &err) failed, bad token starting at %s\n",
+ symbols, err);
+ if (die_on_err)
+ exit(1);
+ } else
+ printf("lio_parse_io_arg2(%s, &err) returned %#o\n",
+ symbols, method);
+
+ exit_status = 0;
+ for (ind = 0; ind < iter; ind++) {
+ memset(buffer, 'A', 4096);
+ if (lseek(fd, 0, 0) == -1) {
+ printf("lseek(fd,0,0), %d, failed, errno %d\n",
+ __LINE__, errno);
+ ++exit_status;
+ }
+ if ((ret = lio_write_buffer(fd, method, buffer,
+ size, SIGUSR1, &err,
+ 0)) != size) {
+ printf
+ ("lio_write_buffer returned -1, err = %s\n",
+ err);
+ } else
+ printf("lio_write_buffer returned %d\n", ret);
+
+ memset(buffer, 'B', 4096);
+ if (lseek(fd, 0, 0) == -1) {
+ printf("lseek(fd,0,0), %d, failed, errno %d\n",
+ __LINE__, errno);
+ ++exit_status;
+ }
+ if ((ret = lio_read_buffer(fd, method, buffer,
+ size, SIGUSR2, &err,
+ 0)) != size) {
+ printf
+ ("lio_read_buffer returned -1, err = %s\n",
+ err);
+ } else
+ printf("lio_read_buffer returned %d\n", ret);
+
+ for (i = 0; i < 4096; ++i) {
+ if (buffer[i] != 'A') {
+ printf(" buffer[%d] = %d\n", i,
+ buffer[i]);
+ ++exit_status;
+ break;
+ }
+ }
+
+ if (exit_status)
+ exit(exit_status);
+
+ }
+
+ unlink("unit_test_file");
+ exit(0);
}
- printf("\n********* read %s ***************\n", Unit_info[ind].str);
- if (lseek(fd, 0, 0) == -1) {
- printf("lseek(fd,0,0), %d, failed, errno %d\n",
- __LINE__, errno );
- ++exit_status;
- }
- memset( buffer, 'B', 4096 );
- if ((ret=lio_read_buffer(fd, Unit_info[ind].method, buffer,
- size, Unit_info[ind].sig, &err, 0)) != size ) {
- printf(">>>>> lio_read_buffer(fd,0%x,buffer,%d,%d,err,0) returned -1,\n err = %s\n",
- Unit_info[ind].method, size, Unit_info[ind].sig, err);
- ++exit_status;
- if (die_on_err)
- exit(exit_status);
- } else {
- printf("lio_read_buffer returned %d\n", ret);
- }
+ for (ind = 0; ind < sizeof(Unit_info) / sizeof(struct unit_info_t);
+ ind++) {
- for (i = 0; i < 4096; ++i) {
- if (buffer[i] != 'A') {
- printf(" buffer[%d] = %d\n", i, buffer[i] );
+ printf("\n********* write %s ***************\n",
+ Unit_info[ind].str);
+ if (lseek(fd, 0, 0) == -1) {
+ printf("lseek(fd,0,0), %d, failed, errno %d\n",
+ __LINE__, errno);
+ ++exit_status;
+ }
+
+ memset(buffer, 'A', 4096);
+ if ((ret = lio_write_buffer(fd, Unit_info[ind].method, buffer,
+ size, Unit_info[ind].sig, &err,
+ 0)) != size) {
+ printf
+ (">>>>> lio_write_buffer(fd,0%x,buffer,%d,%d,err,0) returned -1,\n err = %s\n",
+ Unit_info[ind].method, size, Unit_info[ind].sig,
+ err);
++exit_status;
if (die_on_err)
exit(exit_status);
- break;
+ } else {
+ printf("lio_write_buffer returned %d\n", ret);
}
- }
- fflush(stdout);
- fflush(stderr);
- sleep(1);
+ printf("\n********* read %s ***************\n",
+ Unit_info[ind].str);
+ if (lseek(fd, 0, 0) == -1) {
+ printf("lseek(fd,0,0), %d, failed, errno %d\n",
+ __LINE__, errno);
+ ++exit_status;
+ }
+ memset(buffer, 'B', 4096);
+ if ((ret = lio_read_buffer(fd, Unit_info[ind].method, buffer,
+ size, Unit_info[ind].sig, &err,
+ 0)) != size) {
+ printf
+ (">>>>> lio_read_buffer(fd,0%x,buffer,%d,%d,err,0) returned -1,\n err = %s\n",
+ Unit_info[ind].method, size, Unit_info[ind].sig,
+ err);
+ ++exit_status;
+ if (die_on_err)
+ exit(exit_status);
+ } else {
+ printf("lio_read_buffer returned %d\n", ret);
+ }
- }
+ for (i = 0; i < 4096; ++i) {
+ if (buffer[i] != 'A') {
+ printf(" buffer[%d] = %d\n", i, buffer[i]);
+ ++exit_status;
+ if (die_on_err)
+ exit(exit_status);
+ break;
+ }
+ }
- unlink("unit_test_file");
+ fflush(stdout);
+ fflush(stderr);
+ sleep(1);
- exit(exit_status);
+ }
+
+ unlink("unit_test_file");
+
+ exit(exit_status);
}
#endif
diff --git a/lib/tst_cwd_has_free.c b/lib/tst_cwd_has_free.c
index 18209aa..e44c31f 100644
--- a/lib/tst_cwd_has_free.c
+++ b/lib/tst_cwd_has_free.c
@@ -11,12 +11,12 @@
*/
#include <sys/vfs.h>
-int
-tst_cwd_has_free(int required_kib)
+int tst_cwd_has_free(int required_kib)
{
struct statfs sf;
statfs(".", &sf);
/* check that we have enough blocks to create swap file */
- return ((float)sf.f_bfree)/(1024/sf.f_bsize) >= required_kib?1:0;
+ return ((float)sf.f_bfree) / (1024 / sf.f_bsize) >=
+ required_kib ? 1 : 0;
}
diff --git a/lib/tst_is_cwd.c b/lib/tst_is_cwd.c
index 636aaca..1021660 100644
--- a/lib/tst_is_cwd.c
+++ b/lib/tst_is_cwd.c
@@ -11,7 +11,7 @@
#include <sys/vfs.h>
-#define TMPFS_MAGIC 0x01021994 /* man 2 statfs */
+#define TMPFS_MAGIC 0x01021994 /* man 2 statfs */
int tst_is_cwd_tmpfs(void)
{
struct statfs sf;
@@ -21,7 +21,7 @@
return (sf.f_type == TMPFS_MAGIC);
}
-#define NFS_MAGIC 0x6969 /* man 2 statfs */
+#define NFS_MAGIC 0x6969 /* man 2 statfs */
int tst_is_cwd_nfs(void)
{
struct statfs sf;
@@ -31,14 +31,14 @@
return (sf.f_type == NFS_MAGIC);
}
-#define V9FS_MAGIC 0x01021997 /* kernel-source/include/linux/magic.h */
+#define V9FS_MAGIC 0x01021997 /* kernel-source/include/linux/magic.h */
int tst_is_cwd_v9fs(void)
{
- struct statfs sf;
- statfs(".", &sf);
+ struct statfs sf;
+ statfs(".", &sf);
- /* Verify that the file is not on a nfs filesystem */
- return (sf.f_type == V9FS_MAGIC);
+ /* Verify that the file is not on a nfs filesystem */
+ return (sf.f_type == V9FS_MAGIC);
}
#define RAMFS_MAGIC 0x858458f6
diff --git a/lib/tst_kvercmp.c b/lib/tst_kvercmp.c
index e824295..cb4fd67 100644
--- a/lib/tst_kvercmp.c
+++ b/lib/tst_kvercmp.c
@@ -30,7 +30,6 @@
*
*/
-
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
@@ -42,7 +41,7 @@
char *kver;
char *r1, *r2, *r3;
#if !defined(linux)
- extern char *strsep(); /* shut up some compilers */
+ extern char *strsep(); /* shut up some compilers */
#endif
uname(&uval);
@@ -56,7 +55,8 @@
*k3 = atoi(r3);
}
-int tst_kvercmp(int r1, int r2, int r3) {
+int tst_kvercmp(int r1, int r2, int r3)
+{
int a1, a2, a3;
int testver, currver;
diff --git a/lib/tst_res.c b/lib/tst_res.c
index fc231c4..bbed538 100644
--- a/lib/tst_res.c
+++ b/lib/tst_res.c
@@ -31,7 +31,6 @@
* http://oss.sgi.com/projects/GenInfo/NoticeExplan/
*/
-
/* $Id: tst_res.c,v 1.14 2009/12/01 08:57:20 yaberauneya Exp $ */
/**********************************************************
@@ -105,15 +104,15 @@
/* Break bad habits. */
#ifdef GARRETT_IS_A_PEDANTIC_BASTARD
-pid_t spawned_program_pid;
+pid_t spawned_program_pid;
#endif
-#define VERBOSE 1 /* flag values for the T_mode variable */
+#define VERBOSE 1 /* flag values for the T_mode variable */
#define NOPASS 3
#define DISCARD 4
-#define MAXMESG 80 /* max length of internal messages */
-#define USERMESG 2048 /* max length of user message */
+#define MAXMESG 80 /* max length of internal messages */
+#define USERMESG 2048 /* max length of user message */
#define TRUE 1
#define FALSE 0
@@ -144,37 +143,36 @@
/*
* Define some static/global variables.
*/
-static FILE *T_out = NULL; /* tst_res() output file descriptor */
-static char *File; /* file whose contents is part of result */
-static int T_exitval = 0; /* exit value used by tst_exit() */
-static int T_mode = VERBOSE; /* flag indicating print mode: VERBOSE, */
- /* NOPASS, DISCARD */
+static FILE *T_out = NULL; /* tst_res() output file descriptor */
+static char *File; /* file whose contents is part of result */
+static int T_exitval = 0; /* exit value used by tst_exit() */
+static int T_mode = VERBOSE; /* flag indicating print mode: VERBOSE, */
+ /* NOPASS, DISCARD */
-static char Warn_mesg[MAXMESG]; /* holds warning messages */
+static char Warn_mesg[MAXMESG]; /* holds warning messages */
/*
* These are used for condensing output when NOT in verbose mode.
*/
-static int Buffered = FALSE; /* TRUE if condensed output is currently */
- /* buffered (i.e. not yet printed) */
-static char *Last_tcid; /* previous test case id */
-static int Last_num; /* previous test case number */
-static int Last_type; /* previous test result type */
-static char *Last_mesg; /* previous test result message */
-
+static int Buffered = FALSE; /* TRUE if condensed output is currently */
+ /* buffered (i.e. not yet printed) */
+static char *Last_tcid; /* previous test case id */
+static int Last_num; /* previous test case number */
+static int Last_type; /* previous test result type */
+static char *Last_mesg; /* previous test result message */
/*
* These globals may be externed by the test.
*/
-int Tst_count = 0; /* current count of test cases executed; NOTE: */
- /* Tst_count may be externed by other programs */
+int Tst_count = 0; /* current count of test cases executed; NOTE: */
+ /* Tst_count may be externed by other programs */
/*
* These globals must be defined in the test.
*/
-extern char *TCID; /* Test case identifier from the test source */
-extern int TST_TOTAL; /* Total number of test cases from the test */
- /* source */
+extern char *TCID; /* Test case identifier from the test source */
+extern int TST_TOTAL; /* Total number of test cases from the test */
+ /* source */
struct pair {
const char *name;
@@ -187,6 +185,7 @@
return "???";
return pair[idx].name;
}
+
#define pair_lookup(pair, idx) pair_lookup(pair, ARRAY_SIZE(pair), idx)
/*
@@ -196,12 +195,12 @@
{
struct pair ttype_pairs[] = {
PAIR(TPASS)
- PAIR(TFAIL)
- PAIR(TBROK)
- PAIR(TRETR)
- PAIR(TCONF)
- PAIR(TWARN)
- PAIR(TINFO)
+ PAIR(TFAIL)
+ PAIR(TBROK)
+ PAIR(TRETR)
+ PAIR(TCONF)
+ PAIR(TWARN)
+ PAIR(TINFO)
};
return pair_lookup(ttype_pairs, TTYPE_RESULT(ttype));
}
@@ -213,40 +212,40 @@
{
struct pair errno_pairs[] = {
PAIR(EPERM)
- PAIR(ENOENT)
- PAIR(ESRCH)
- PAIR(EINTR)
- PAIR(EIO)
- PAIR(ENXIO)
- PAIR(E2BIG)
- PAIR(ENOEXEC)
- PAIR(EBADF)
- PAIR(ECHILD)
- PAIR(EAGAIN)
- PAIR(ENOMEM)
- PAIR(EACCES)
- PAIR(EFAULT)
- PAIR(ENOTBLK)
- PAIR(EBUSY)
- PAIR(EEXIST)
- PAIR(EXDEV)
- PAIR(ENODEV)
- PAIR(ENOTDIR)
- PAIR(EISDIR)
- PAIR(EINVAL)
- PAIR(ENFILE)
- PAIR(EMFILE)
- PAIR(ENOTTY)
- PAIR(ETXTBSY)
- PAIR(EFBIG)
- PAIR(ENOSPC)
- PAIR(ESPIPE)
- PAIR(EROFS)
- PAIR(EMLINK)
- PAIR(EPIPE)
- PAIR(EDOM)
- PAIR(ERANGE)
- PAIR(ENAMETOOLONG)
+ PAIR(ENOENT)
+ PAIR(ESRCH)
+ PAIR(EINTR)
+ PAIR(EIO)
+ PAIR(ENXIO)
+ PAIR(E2BIG)
+ PAIR(ENOEXEC)
+ PAIR(EBADF)
+ PAIR(ECHILD)
+ PAIR(EAGAIN)
+ PAIR(ENOMEM)
+ PAIR(EACCES)
+ PAIR(EFAULT)
+ PAIR(ENOTBLK)
+ PAIR(EBUSY)
+ PAIR(EEXIST)
+ PAIR(EXDEV)
+ PAIR(ENODEV)
+ PAIR(ENOTDIR)
+ PAIR(EISDIR)
+ PAIR(EINVAL)
+ PAIR(ENFILE)
+ PAIR(EMFILE)
+ PAIR(ENOTTY)
+ PAIR(ETXTBSY)
+ PAIR(EFBIG)
+ PAIR(ENOSPC)
+ PAIR(ESPIPE)
+ PAIR(EROFS)
+ PAIR(EMLINK)
+ PAIR(EPIPE)
+ PAIR(EDOM)
+ PAIR(ERANGE)
+ PAIR(ENAMETOOLONG)
};
return pair_lookup(errno_pairs, err);
}
@@ -301,7 +300,7 @@
} else {
if (Tst_count < 0)
tst_print(TCID, 0, TWARN,
- "tst_res(): Tst_count < 0 is not valid");
+ "tst_res(): Tst_count < 0 is not valid");
/*
* Process each display type.
@@ -309,11 +308,11 @@
switch (T_mode) {
case DISCARD:
break;
- case NOPASS: /* filtered by tst_print() */
- tst_condense(Tst_count+1, ttype, tmesg);
+ case NOPASS: /* filtered by tst_print() */
+ tst_condense(Tst_count + 1, ttype, tmesg);
break;
- default: /* VERBOSE */
- tst_print(TCID, Tst_count+1, ttype, tmesg);
+ default: /* VERBOSE */
+ tst_print(TCID, Tst_count + 1, ttype, tmesg);
break;
}
@@ -322,7 +321,6 @@
}
-
/*
* tst_condense() - Handle test cases in NOPASS mode (i.e.
* buffer the current result and print the last result
@@ -336,9 +334,8 @@
int ttype_result = TTYPE_RESULT(ttype);
#if DEBUG
- printf( "IN tst_condense: tcid = %s, tnum = %d, ttype = %d, "
- "tmesg = %s\n",
- TCID, tnum, ttype, tmesg);
+ printf("IN tst_condense: tcid = %s, tnum = %d, ttype = %d, "
+ "tmesg = %s\n", TCID, tnum, ttype, tmesg);
fflush(stdout);
#endif
@@ -381,7 +378,6 @@
}
}
-
/*
* tst_flush() - Print any messages pending because due to tst_condense,
* and flush T_out.
@@ -404,7 +400,6 @@
fflush(T_out);
}
-
/*
* tst_print() - Print a line to the output stream.
*/
@@ -443,7 +438,7 @@
#if DEBUG
printf("IN tst_print: tnum = %d, ttype = %d, tmesg = %s\n",
- tnum, ttype, tmesg);
+ tnum, ttype, tmesg);
fflush(stdout);
#endif
@@ -463,7 +458,8 @@
* through tst_res() (e.g. internal TWARN messages).
*/
if (T_mode == DISCARD || (T_mode == NOPASS && ttype_result != TFAIL &&
- ttype_result != TBROK && ttype_result != TWARN))
+ ttype_result != TBROK
+ && ttype_result != TWARN))
return;
/*
@@ -472,12 +468,11 @@
type = strttype(ttype);
if (T_mode == VERBOSE) {
size = snprintf(message, sizeof(message),
- "%-8s %4d %s : %s",
- tcid, tnum, type, tmesg);
+ "%-8s %4d %s : %s", tcid, tnum, type, tmesg);
} else {
size = snprintf(message, sizeof(message),
- "%-8s %4d %s : %s",
- tcid, tnum, type, tmesg);
+ "%-8s %4d %s : %s",
+ tcid, tnum, type, tmesg);
}
if (size >= sizeof(message)) {
@@ -487,8 +482,8 @@
if (ttype & TERRNO) {
size += snprintf(message + size, sizeof(message) - size,
- ": errno=%s(%i): %s", strerrnodef(err),
- err, strerror(err));
+ ": errno=%s(%i): %s", strerrnodef(err),
+ err, strerror(err));
}
if (size >= sizeof(message)) {
@@ -498,9 +493,9 @@
if (ttype & TTERRNO) {
size += snprintf(message + size, sizeof(message) - size,
- ": TEST_ERRNO=%s(%i): %s",
- strerrnodef(TEST_ERRNO), (int)TEST_ERRNO,
- strerror(TEST_ERRNO));
+ ": TEST_ERRNO=%s(%i): %s",
+ strerrnodef(TEST_ERRNO), (int)TEST_ERRNO,
+ strerror(TEST_ERRNO));
}
if (size + 1 >= sizeof(message)) {
@@ -508,8 +503,8 @@
abort();
}
- message[size] = '\n';
- message[size+1] = '\0';
+ message[size] = '\n';
+ message[size + 1] = '\0';
fputs(message, T_out);
@@ -523,7 +518,6 @@
File = NULL;
}
-
/*
* check_env() - Check the value of the environment variable TOUTPUT and
* set the global variable T_mode. The TOUTPUT environment
@@ -534,7 +528,7 @@
static void check_env(void)
{
static int first_time = 1;
- char *value;
+ char *value;
#if DEBUG
printf("IN check_env\n");
@@ -547,7 +541,7 @@
first_time = 0;
/* BTOUTPUT not defined, use default */
- if ((value = getenv(TOUTPUT)) == NULL) {
+ if ((value = getenv(TOUTPUT)) == NULL) {
T_mode = VERBOSE;
return;
}
@@ -567,7 +561,6 @@
return;
}
-
/*
* tst_exit() - Call exit() with the value T_exitval, set up by
* tst_res(). T_exitval has a bit set for most of the
@@ -578,7 +571,8 @@
void tst_exit(void)
{
#if DEBUG
- printf("IN tst_exit\n"); fflush(stdout);
+ printf("IN tst_exit\n");
+ fflush(stdout);
fflush(stdout);
#endif
@@ -589,7 +583,6 @@
exit(T_exitval & ~(TRETR | TINFO | TCONF));
}
-
/*
* tst_environ() - Preserve the tst_res() output location, despite any
* changes to stdout.
@@ -602,7 +595,6 @@
return 0;
}
-
/*
* Make tst_brk reentrant so that one can call the SAFE_* macros from within
* user-defined cleanup functions.
@@ -613,13 +605,14 @@
* tst_brk() - Fail or break current test case, and break the remaining
* tests cases.
*/
-void tst_brk(int ttype, char *fname, void (*func)(void), char *arg_fmt, ...)
+void tst_brk(int ttype, char *fname, void (*func) (void), char *arg_fmt, ...)
{
char tmesg[USERMESG];
int ttype_result = TTYPE_RESULT(ttype);
#if DEBUG
- printf("IN tst_brk\n"); fflush(stdout);
+ printf("IN tst_brk\n");
+ fflush(stdout);
fflush(stdout);
#endif
@@ -641,8 +634,8 @@
if (tst_brk_entered == 0) {
if (ttype_result == TCONF)
tst_res(ttype, NULL,
- "Remaining cases not appropriate for "
- "configuration");
+ "Remaining cases not appropriate for "
+ "configuration");
else if (ttype_result == TRETR)
tst_res(ttype, NULL, "Remaining cases retired");
else if (ttype_result == TBROK)
@@ -655,7 +648,7 @@
*/
if (func != NULL) {
tst_brk_entered++;
- (*func)();
+ (*func) ();
tst_brk_entered--;
}
if (tst_brk_entered == 0)
@@ -671,7 +664,8 @@
char tmesg[USERMESG];
#if DEBUG
- printf("IN tst_resm\n"); fflush(stdout);
+ printf("IN tst_resm\n");
+ fflush(stdout);
fflush(stdout);
#endif
@@ -680,16 +674,16 @@
tst_res(ttype, NULL, "%s", tmesg);
}
-
/*
* tst_brkm() - Interface to tst_brk(), with no filename.
*/
-void tst_brkm(int ttype, void (*func)(void), char *arg_fmt, ...)
+void tst_brkm(int ttype, void (*func) (void), char *arg_fmt, ...)
{
char tmesg[USERMESG];
#if DEBUG
- printf("IN tst_brkm\n"); fflush(stdout);
+ printf("IN tst_brkm\n");
+ fflush(stdout);
fflush(stdout);
#endif
@@ -698,35 +692,34 @@
tst_brk(ttype, NULL, func, "%s", tmesg);
}
-
/*
* tst_require_root() - Test for root permissions and abort if not.
*/
-void tst_require_root(void (*func)(void))
+void tst_require_root(void (*func) (void))
{
if (geteuid() != 0)
tst_brkm(TCONF, func, "Test needs to be run as root");
}
-
/*
* cat_file() - Print the contents of a file to standard out.
*/
static void cat_file(char *filename)
{
FILE *fp;
- int b_read, b_written;
+ int b_read, b_written;
char buffer[BUFSIZ];
#if DEBUG
- printf("IN cat_file\n"); fflush(stdout);
+ printf("IN cat_file\n");
+ fflush(stdout);
#endif
if ((fp = fopen(filename, "r")) == NULL) {
sprintf(Warn_mesg,
"tst_res(): fopen(%s, \"r\") failed; errno = %d: %s",
filename, errno, strerror(errno));
- tst_print(TCID, 0, TWARN, Warn_mesg);
+ tst_print(TCID, 0, TWARN, Warn_mesg);
return;
}
@@ -760,14 +753,13 @@
}
}
-
#ifdef UNIT_TEST
/****************************************************************************
* Unit test code: Takes input from stdin and can make the following
* calls: tst_res(), tst_resm(), tst_brk(), tst_brkm(),
* tst_flush_buf(), tst_exit().
****************************************************************************/
-int TST_TOTAL = 10;
+int TST_TOTAL = 10;
char *TCID = "TESTTCID";
#define RES "tst_res.c UNIT TEST message; ttype = %d; contents of \"%s\":"
@@ -775,7 +767,7 @@
int main(void)
{
- int ttype;
+ int ttype;
char chr;
char fname[MAXMESG];
@@ -790,12 +782,11 @@
%2i : call tst_res(TWARN, ...)\n\
%2i : call tst_res(TRETR, ...)\n\
%2i : call tst_res(TINFO, ...)\n\
- %2i : call tst_res(TCONF, ...)\n\n",
- TPASS, TFAIL, TBROK, TWARN, TRETR, TINFO, TCONF);
+ %2i : call tst_res(TCONF, ...)\n\n", TPASS, TFAIL, TBROK, TWARN, TRETR, TINFO, TCONF);
while (1) {
printf("Enter ttype (-5,-4,-3,-2,-1,%i,%i,%i,%i,%i,%i,%i): ",
- TPASS, TFAIL, TBROK, TWARN, TRETR, TINFO, TCONF);
+ TPASS, TFAIL, TBROK, TWARN, TRETR, TINFO, TCONF);
scanf("%d%c", &ttype, &chr);
switch (ttype) {
@@ -808,20 +799,23 @@
break;
case -3:
- printf("Enter the current type (%i=FAIL, %i=BROK, %i=RETR, %i=CONF): ",
- TFAIL, TBROK, TRETR, TCONF);
+ printf
+ ("Enter the current type (%i=FAIL, %i=BROK, %i=RETR, %i=CONF): ",
+ TFAIL, TBROK, TRETR, TCONF);
scanf("%d%c", &ttype, &chr);
printf("Enter file name (<cr> for none): ");
gets(fname);
if (strcmp(fname, "") == 0)
tst_brkm(ttype, tst_exit, RESM, ttype);
else
- tst_brk(ttype, fname, tst_exit, RES, ttype, fname);
- break;
+ tst_brk(ttype, fname, tst_exit, RES, ttype,
+ fname);
+ break;
case -4:
- printf("Enter the current type (%i,%i,%i,%i,%i,%i,%i): ",
- TPASS, TFAIL, TBROK, TWARN, TRETR, TINFO, TCONF);
+ printf
+ ("Enter the current type (%i,%i,%i,%i,%i,%i,%i): ",
+ TPASS, TFAIL, TBROK, TWARN, TRETR, TINFO, TCONF);
scanf("%d%c", &ttype, &chr);
default:
printf("Enter file name (<cr> for none): ");
diff --git a/lib/tst_sig.c b/lib/tst_sig.c
index 5bc6c0c..2ffe610 100644
--- a/lib/tst_sig.c
+++ b/lib/tst_sig.c
@@ -179,11 +179,11 @@
#ifdef CRAY
case SIGINFO:
case SIGRECOVERY: /* allow chkpnt/restart */
-#endif /* CRAY */
+#endif /* CRAY */
#ifdef SIGSWAP
case SIGSWAP:
-#endif /* SIGSWAP */
+#endif /* SIGSWAP */
#ifdef SIGCKPT
case SIGCKPT:
@@ -198,10 +198,10 @@
*/
#ifdef SIGPTINTR
case SIGPTINTR:
-#endif /* SIGPTINTR */
+#endif /* SIGPTINTR */
#ifdef SIGPTRESCHED
case SIGPTRESCHED:
-#endif /* SIGPTRESCHED */
+#endif /* SIGPTRESCHED */
#ifdef _SIGRESERVE
case _SIGRESERVE:
#endif
@@ -222,15 +222,15 @@
default:
if (tst_setup_signal(sig, handler) == SIG_ERR)
- tst_resm(TWARN|TERRNO,
- "signal failed for signal %d", sig);
+ tst_resm(TWARN | TERRNO,
+ "signal failed for signal %d", sig);
break;
}
#ifdef __sgi
/* On irix (07/96), signal() fails when signo is 33 or higher */
if (sig + 1 >= 33)
break;
-#endif /* __sgi */
+#endif /* __sgi */
} /* endfor */
}
@@ -246,15 +246,14 @@
* Break remaining test cases, do any cleanup, then exit
*/
tst_brkm(TBROK, T_cleanup,
- "unexpected signal %d received (pid = %d).", sig, getpid());
+ "unexpected signal %d received (pid = %d).", sig, getpid());
}
/*
* tst_setup_signal - A function like signal(), but we have
* control over its personality.
*/
-static void (*tst_setup_signal(int sig, void (*handler) (int))) (int)
-{
+static void (*tst_setup_signal(int sig, void (*handler) (int))) (int) {
struct sigaction my_act, old_act;
int ret;
diff --git a/lib/tst_tmpdir.c b/lib/tst_tmpdir.c
index 90c8945..0a17fcc 100644
--- a/lib/tst_tmpdir.c
+++ b/lib/tst_tmpdir.c
@@ -119,26 +119,24 @@
* use our default TEMPDIR.
*/
if ((env_tmpdir = getenv("TMPDIR")))
- snprintf(template, PATH_MAX, "%s/%.3sXXXXXX",
- env_tmpdir, TCID);
+ snprintf(template, PATH_MAX, "%s/%.3sXXXXXX", env_tmpdir, TCID);
else
- snprintf(template, PATH_MAX, "%s/%.3sXXXXXX",
- TEMPDIR, TCID);
+ snprintf(template, PATH_MAX, "%s/%.3sXXXXXX", TEMPDIR, TCID);
/* Make the temporary directory in one shot using mkdtemp. */
if (mkdtemp(template) == NULL)
- tst_brkm(TBROK|TERRNO, tmpdir_cleanup,
- "%s: mkdtemp(%s) failed", __func__, template);
+ tst_brkm(TBROK | TERRNO, tmpdir_cleanup,
+ "%s: mkdtemp(%s) failed", __func__, template);
if ((TESTDIR = strdup(template)) == NULL)
- tst_brkm(TBROK|TERRNO, tmpdir_cleanup,
- "%s: strdup(%s) failed", __func__, template);
+ tst_brkm(TBROK | TERRNO, tmpdir_cleanup,
+ "%s: strdup(%s) failed", __func__, template);
if (chown(TESTDIR, -1, getgid()) == -1)
- tst_brkm(TBROK|TERRNO, tmpdir_cleanup,
- "chown(%s, -1, %d) failed", TESTDIR, getgid());
+ tst_brkm(TBROK | TERRNO, tmpdir_cleanup,
+ "chown(%s, -1, %d) failed", TESTDIR, getgid());
if (chmod(TESTDIR, DIR_MODE) == -1)
- tst_brkm(TBROK|TERRNO, tmpdir_cleanup,
- "chmod(%s, %#o) failed", TESTDIR, DIR_MODE);
+ tst_brkm(TBROK | TERRNO, tmpdir_cleanup,
+ "chmod(%s, %#o) failed", TESTDIR, DIR_MODE);
/*
* Change to the temporary directory. If the chdir() fails, issue
@@ -147,13 +145,13 @@
* fails, also issue a TWARN message.
*/
if (chdir(TESTDIR) == -1) {
- tst_brkm(TBROK|TERRNO, NULL, "%s: chdir(%s) failed",
- __func__, TESTDIR);
+ tst_brkm(TBROK | TERRNO, NULL, "%s: chdir(%s) failed",
+ __func__, TESTDIR);
/* Try to remove the directory */
if (rmobj(TESTDIR, &errmsg) == -1)
tst_resm(TWARN, "%s: rmobj(%s) failed: %s",
- __func__, TESTDIR, errmsg);
+ __func__, TESTDIR, errmsg);
tmpdir_cleanup();
}
@@ -171,14 +169,15 @@
*/
if (TESTDIR == NULL) {
tst_resm(TWARN,
- "%s: TESTDIR was NULL; no removal attempted", __func__);
+ "%s: TESTDIR was NULL; no removal attempted",
+ __func__);
return;
}
if ((parent_dir = malloc(PATH_MAX)) == NULL) {
/* Make sure that we exit quickly and noisily. */
- tst_brkm(TBROK|TERRNO, NULL,
- "%s: malloc(%d) failed", __func__, PATH_MAX);
+ tst_brkm(TBROK | TERRNO, NULL,
+ "%s: malloc(%d) failed", __func__, PATH_MAX);
}
/*
@@ -195,7 +194,7 @@
}
if ((parent_dir = dirname(parent_dir)) == NULL) {
- tst_resm(TWARN|TERRNO, "%s: dirname failed", __func__);
+ tst_resm(TWARN | TERRNO, "%s: dirname failed", __func__);
return;
}
@@ -203,9 +202,9 @@
* Change directory to parent_dir (The dir above TESTDIR).
*/
if (chdir(parent_dir) != 0) {
- tst_resm(TWARN|TERRNO,
- "%s: chdir(%s) failed\nAttempting to remove temp dir "
- "anyway", __func__, parent_dir);
+ tst_resm(TWARN | TERRNO,
+ "%s: chdir(%s) failed\nAttempting to remove temp dir "
+ "anyway", __func__, parent_dir);
}
/*
@@ -213,10 +212,9 @@
*/
if (rmobj(TESTDIR, &errmsg) == -1)
tst_resm(TWARN, "%s: rmobj(%s) failed: %s",
- __func__, TESTDIR, errmsg);
+ __func__, TESTDIR, errmsg);
}
-
/*
* tmpdir_cleanup(void) - This function is used when tst_tmpdir()
* encounters an error, and must cleanup and exit.
@@ -226,6 +224,6 @@
static void tmpdir_cleanup(void)
{
tst_brkm(TWARN, NULL,
- "%s: no user cleanup function called before exiting", __func__);
+ "%s: no user cleanup function called before exiting",
+ __func__);
}
-
diff --git a/lib/write_log.c b/lib/write_log.c
index 989455b..1731dc3 100644
--- a/lib/write_log.c
+++ b/lib/write_log.c
@@ -86,14 +86,14 @@
/*#define PATH_MAX pathconf("/", _PC_PATH_MAX)*/
#endif
-char Wlog_Error_String[256];
+char Wlog_Error_String[256];
#if __STDC__
-static int wlog_rec_pack(struct wlog_rec *wrec, char *buf, int flag);
-static int wlog_rec_unpack(struct wlog_rec *wrec, char *buf);
+static int wlog_rec_pack(struct wlog_rec *wrec, char *buf, int flag);
+static int wlog_rec_unpack(struct wlog_rec *wrec, char *buf);
#else
-static int wlog_rec_pack();
-static int wlog_rec_unpack();
+static int wlog_rec_pack();
+static int wlog_rec_unpack();
#endif
/*
@@ -110,13 +110,12 @@
* umask.
*/
-int
-wlog_open(wfile, trunc, mode)
-struct wlog_file *wfile;
-int trunc;
-int mode;
+int wlog_open(wfile, trunc, mode)
+struct wlog_file *wfile;
+int trunc;
+int mode;
{
- int omask, oflags;
+ int omask, oflags;
if (trunc)
trunc = O_TRUNC;
@@ -128,8 +127,7 @@
*/
oflags = O_WRONLY | O_APPEND | O_CREAT | trunc;
- wfile->w_afd =
- open(wfile->w_file, oflags, mode);
+ wfile->w_afd = open(wfile->w_file, oflags, mode);
umask(omask);
if (wfile->w_afd == -1) {
@@ -161,9 +159,8 @@
* with the wlog_open() call.
*/
-int
-wlog_close(wfile)
-struct wlog_file *wfile;
+int wlog_close(wfile)
+struct wlog_file *wfile;
{
close(wfile->w_afd);
close(wfile->w_rfd);
@@ -196,67 +193,67 @@
* place before the record is written.
*/
-int
-wlog_record_write(wfile, wrec, offset)
-struct wlog_file *wfile;
-struct wlog_rec *wrec;
-long offset;
+int wlog_record_write(wfile, wrec, offset)
+struct wlog_file *wfile;
+struct wlog_rec *wrec;
+long offset;
{
- int reclen;
- char wbuf[WLOG_REC_MAX_SIZE + 2];
+ int reclen;
+ char wbuf[WLOG_REC_MAX_SIZE + 2];
- /*
- * If offset is -1, we append the record at the end of file
- *
- * Otherwise, we overlay wrec at the file offset indicated and assume
- * that the caller passed us the correct offset. We do not record the
- * fname in this case.
- */
-
- reclen = wlog_rec_pack(wrec, wbuf, (offset < 0));
-
- if (offset < 0) {
/*
- * Since we're writing a complete new record, we must also tack
- * its length onto the end so that wlog_scan_backward() will work.
- * Length is asumed to fit into 2 bytes.
+ * If offset is -1, we append the record at the end of file
+ *
+ * Otherwise, we overlay wrec at the file offset indicated and assume
+ * that the caller passed us the correct offset. We do not record the
+ * fname in this case.
*/
- wbuf[reclen] = reclen / 256;
- wbuf[reclen+1] = reclen % 256;
- reclen += 2;
+ reclen = wlog_rec_pack(wrec, wbuf, (offset < 0));
- if (write(wfile->w_afd, wbuf, reclen) == -1) {
- sprintf(Wlog_Error_String,
- "Could not write log - write(%s, %s, %d) failed: %s\n",
- wfile->w_file, wbuf, reclen, strerror(errno));
- return -1;
- } else {
- offset = lseek(wfile->w_afd, 0, SEEK_CUR) - reclen;
- if (offset == -1) {
- sprintf(Wlog_Error_String,
- "Could not reposition file pointer - lseek(%s, 0, SEEK_CUR) failed: %s\n",
- wfile->w_file, strerror(errno));
- return -1;
- }
- }
- } else {
- if ((lseek(wfile->w_rfd, offset, SEEK_SET)) == -1) {
- sprintf(Wlog_Error_String,
- "Could not reposition file pointer - lseek(%s, %ld, SEEK_SET) failed: %s\n",
- wfile->w_file, offset, strerror(errno));
- return -1;
- } else {
- if ((write(wfile->w_rfd, wbuf, reclen)) == -1) {
- sprintf(Wlog_Error_String,
- "Could not write log - write(%s, %s, %d) failed: %s\n",
- wfile->w_file, wbuf, reclen, strerror(errno));
- return -1;
- }
- }
- }
+ if (offset < 0) {
+ /*
+ * Since we're writing a complete new record, we must also tack
+ * its length onto the end so that wlog_scan_backward() will work.
+ * Length is asumed to fit into 2 bytes.
+ */
- return offset;
+ wbuf[reclen] = reclen / 256;
+ wbuf[reclen + 1] = reclen % 256;
+ reclen += 2;
+
+ if (write(wfile->w_afd, wbuf, reclen) == -1) {
+ sprintf(Wlog_Error_String,
+ "Could not write log - write(%s, %s, %d) failed: %s\n",
+ wfile->w_file, wbuf, reclen, strerror(errno));
+ return -1;
+ } else {
+ offset = lseek(wfile->w_afd, 0, SEEK_CUR) - reclen;
+ if (offset == -1) {
+ sprintf(Wlog_Error_String,
+ "Could not reposition file pointer - lseek(%s, 0, SEEK_CUR) failed: %s\n",
+ wfile->w_file, strerror(errno));
+ return -1;
+ }
+ }
+ } else {
+ if ((lseek(wfile->w_rfd, offset, SEEK_SET)) == -1) {
+ sprintf(Wlog_Error_String,
+ "Could not reposition file pointer - lseek(%s, %ld, SEEK_SET) failed: %s\n",
+ wfile->w_file, offset, strerror(errno));
+ return -1;
+ } else {
+ if ((write(wfile->w_rfd, wbuf, reclen)) == -1) {
+ sprintf(Wlog_Error_String,
+ "Could not write log - write(%s, %s, %d) failed: %s\n",
+ wfile->w_file, wbuf, reclen,
+ strerror(errno));
+ return -1;
+ }
+ }
+ }
+
+ return offset;
}
/*
@@ -267,17 +264,16 @@
* will be passed a single parameter - a wlog_rec structure .
*/
-int
-wlog_scan_backward(wfile, nrecs, func, data)
-struct wlog_file *wfile;
-int nrecs;
-int (*func)();
-long data;
+int wlog_scan_backward(wfile, nrecs, func, data)
+struct wlog_file *wfile;
+int nrecs;
+int (*func) ();
+long data;
{
- int fd, leftover, nbytes, offset, recnum, reclen, rval;
- char buf[BSIZE*32], *bufend, *cp, *bufstart;
- char albuf[WLOG_REC_MAX_SIZE];
- struct wlog_rec wrec;
+ int fd, leftover, nbytes, offset, recnum, reclen, rval;
+ char buf[BSIZE * 32], *bufend, *cp, *bufstart;
+ char albuf[WLOG_REC_MAX_SIZE];
+ struct wlog_rec wrec;
fd = wfile->w_rfd;
@@ -285,19 +281,19 @@
* Move to EOF. offset will always hold the current file offset
*/
- if ((lseek(fd, 0, SEEK_END)) == -1) {
- sprintf(Wlog_Error_String,
- "Could not reposition file pointer - lseek(%s, 0, SEEK_END) failed: %s\n",
- wfile->w_file, strerror(errno));
- return -1;
- }
+ if ((lseek(fd, 0, SEEK_END)) == -1) {
+ sprintf(Wlog_Error_String,
+ "Could not reposition file pointer - lseek(%s, 0, SEEK_END) failed: %s\n",
+ wfile->w_file, strerror(errno));
+ return -1;
+ }
offset = lseek(fd, 0, SEEK_CUR);
- if ((offset == -1)) {
- sprintf(Wlog_Error_String,
- "Could not reposition file pointer - lseek(%s, 0, SEEK_CUR) failed: %s\n",
- wfile->w_file, strerror(errno));
- return -1;
- }
+ if ((offset == -1)) {
+ sprintf(Wlog_Error_String,
+ "Could not reposition file pointer - lseek(%s, 0, SEEK_CUR) failed: %s\n",
+ wfile->w_file, strerror(errno));
+ return -1;
+ }
bufend = buf + sizeof(buf);
bufstart = buf;
@@ -320,12 +316,12 @@
/*
* Move to the proper file offset, and read into buf
*/
- if ((lseek(fd, offset, SEEK_SET)) ==-1) {
- sprintf(Wlog_Error_String,
- "Could not reposition file pointer - lseek(%s, %d, SEEK_SET) failed: %s\n",
- wfile->w_file, offset, strerror(errno));
- return -1;
- }
+ if ((lseek(fd, offset, SEEK_SET)) == -1) {
+ sprintf(Wlog_Error_String,
+ "Could not reposition file pointer - lseek(%s, %d, SEEK_SET) failed: %s\n",
+ wfile->w_file, offset, strerror(errno));
+ return -1;
+ }
nbytes = read(fd, bufstart, bufend - bufstart - leftover);
@@ -333,7 +329,8 @@
sprintf(Wlog_Error_String,
"Could not read history file at offset %d - read(%d, %p, %d) failed: %s\n",
offset, fd, bufstart,
- (int)(bufend - bufstart - leftover), strerror(errno));
+ (int)(bufend - bufstart - leftover),
+ strerror(errno));
return -1;
}
@@ -360,7 +357,7 @@
* not be word aligned.
*/
- reclen = (*(cp-2) * 256) + *(cp -1);
+ reclen = (*(cp - 2) * 256) + *(cp - 1);
/*
* If cp-bufstart isn't large enough to hold a
@@ -392,7 +389,7 @@
* stop if instructed to.
*/
- if ((rval = (*func)(&wrec, data)) == WLOG_STOP_SCAN) {
+ if ((rval = (*func) (&wrec, data)) == WLOG_STOP_SCAN) {
break;
}
@@ -413,27 +410,27 @@
* these routines must be reflected in the other.
*/
-static int
-wlog_rec_pack(wrec, buf, flag)
-struct wlog_rec *wrec;
-char *buf;
-int flag;
+static int wlog_rec_pack(wrec, buf, flag)
+struct wlog_rec *wrec;
+char *buf;
+int flag;
{
- char *file, *host, *pattern;
- struct wlog_rec_disk *wrecd;
+ char *file, *host, *pattern;
+ struct wlog_rec_disk *wrecd;
wrecd = (struct wlog_rec_disk *)buf;
- wrecd->w_pid = (uint)wrec->w_pid;
- wrecd->w_offset = (uint)wrec->w_offset;
- wrecd->w_nbytes = (uint)wrec->w_nbytes;
- wrecd->w_oflags = (uint)wrec->w_oflags;
- wrecd->w_done = (uint)wrec->w_done;
- wrecd->w_async = (uint)wrec->w_async;
+ wrecd->w_pid = (uint) wrec->w_pid;
+ wrecd->w_offset = (uint) wrec->w_offset;
+ wrecd->w_nbytes = (uint) wrec->w_nbytes;
+ wrecd->w_oflags = (uint) wrec->w_oflags;
+ wrecd->w_done = (uint) wrec->w_done;
+ wrecd->w_async = (uint) wrec->w_async;
- wrecd->w_pathlen = (wrec->w_pathlen > 0) ? (uint)wrec->w_pathlen : 0;
- wrecd->w_hostlen = (wrec->w_hostlen > 0) ? (uint)wrec->w_hostlen : 0;
- wrecd->w_patternlen = (wrec->w_patternlen > 0) ? (uint)wrec->w_patternlen : 0;
+ wrecd->w_pathlen = (wrec->w_pathlen > 0) ? (uint) wrec->w_pathlen : 0;
+ wrecd->w_hostlen = (wrec->w_hostlen > 0) ? (uint) wrec->w_hostlen : 0;
+ wrecd->w_patternlen =
+ (wrec->w_patternlen > 0) ? (uint) wrec->w_patternlen : 0;
/*
* If flag is true, we should also pack the variable length parts
@@ -456,19 +453,19 @@
memcpy(pattern, wrec->w_pattern, wrecd->w_patternlen);
return (sizeof(struct wlog_rec_disk) +
- wrecd->w_pathlen + wrecd->w_hostlen + wrecd->w_patternlen);
+ wrecd->w_pathlen + wrecd->w_hostlen +
+ wrecd->w_patternlen);
} else {
return sizeof(struct wlog_rec_disk);
}
}
-static int
-wlog_rec_unpack(wrec, buf)
-struct wlog_rec *wrec;
-char *buf;
+static int wlog_rec_unpack(wrec, buf)
+struct wlog_rec *wrec;
+char *buf;
{
- char *file, *host, *pattern;
- struct wlog_rec_disk *wrecd;
+ char *file, *host, *pattern;
+ struct wlog_rec_disk *wrecd;
memset((char *)wrec, 0x00, sizeof(struct wlog_rec));
wrecd = (struct wlog_rec_disk *)buf;
@@ -495,7 +492,7 @@
if (wrec->w_patternlen > 0) {
pattern = buf + sizeof(struct wlog_rec_disk) +
- wrec->w_pathlen + wrec->w_hostlen;
+ wrec->w_pathlen + wrec->w_hostlen;
memcpy(wrec->w_pattern, pattern, wrec->w_patternlen);
}