int
main(int argc, char **argv)
{
    char buffer[1024];
    FILE *in, *out;
    int result;
    int lineno;

    Opt_Parse(argc, argv, options, Opt_Number(options), 0);

    if (version) {
	printVersion(RcsId);
	exit(0);
    }

    in = zopen(inFile, "r");
    if (in == NULL) {
	perror(inFile);
	exit(1);
    }

    out = zopen(outFile, "w");
    if (out == NULL) {
	perror(outFile);
	exit(1);
    }

    lineno = 0;
    while ((numLines == 0 || lineno < numLines) &&
           fgets(buffer, sizeof(buffer), in))
    {
	fputs(buffer, out);
	lineno ++;
    }

    result = zclose(in);
    fprintf(stderr, "zclose(in) = %d\n", result);

    result = zclose(out);
    fprintf(stderr, "zclose(out) = %d\n", result);

    exit(0);
}
Esempio n. 2
0
File: copyin.c Progetto: npe9/sprite
	 "Exercise Sprite's copyin routine by passing various amounts\n\
from a dummy buffer to the kernel and reporting the elapsed time."},
    {OPT_TRUE, "cow", (Address)&spoilCOW,
	 "Prevent copy-on-write from improving the numbers"},
    {OPT_INT, "iter", (Address)&iterations,
	 "Number of times to copy the buffer for each copy amount"},
    {OPT_TRUE, "ma", (Address)&useMakeAccessible,
	 "Use Vm_MakeAccessible instead of Vm_CopyIn"},
    {OPT_TRUE, "out", (Address)&copyout,
	 "Do copyout instead of copyin"},
    {OPT_TRUE, "offset", (Address)&offsetBuf,
	 "Prevent copy-on-write by making the buffer non-page-aligned."},
    {OPT_TRUE, "inband", (Address)&inband,
	 "Use MIG to transfer the buffer instead of copyin/copyout."},
};
int	numOptions = Opt_Number(optionArray);

void WriteToBuffer();
#ifdef DEBUG
void InitBuf(), CheckBuf();
#endif

main(argc, argv)
    int argc;
    char *argv[];
{
    register int i;
    Time startTime, endTime, totalTime;
    int sizeIndex;
    ReturnStatus status;
    int command;		/* "copyin" versus "make accessible" */
Esempio n. 3
0
int
main(int argc, char **argv)
{
    size_t nbytes, minsize, maxsize;
    void *mem;

    Opt_Parse(argc, argv, options, Opt_Number(options), 0);

    /* 
     * Search for the largest power of 2 size that can be allocated
     */
    for (nbytes = 1; nbytes < ULONG_MAX/2; nbytes *= 2) {
	mem = malloc(nbytes * 2);

	if (debug > 0) {
	    fprintf(stderr, "trying %lu -- %s\n", (unsigned long)nbytes * 2,
					mem == 0 ? "FAILED" : "SUCCESS");
	}

	if (mem == 0) break;
	
	free(mem);
    }


    /* 
     * Now do a binary search to find the upper bound
     */
    minsize = nbytes;
    if (nbytes < ULONG_MAX/2) {
	maxsize = nbytes * 2;
    } else {
	maxsize = ULONG_MAX;
    }

    while (minsize < maxsize - 1) {
	nbytes = minsize + (maxsize - minsize)/2;

	mem = malloc(nbytes);

	if (mem == 0) {
	    maxsize = nbytes - 1;
	} else {
	    minsize = nbytes;
	}

	if (debug > 0) {
	    fprintf(stderr, "trying %lu -- %s\n", (unsigned long)nbytes,
					mem == 0 ? "FAILED" : "SUCCESS");
	}

	free(mem);
    }

    printf("managed to allocate %lu bytes (%f Mbytes, %f Gbytes)\n",
				(unsigned long)nbytes,
				nbytes / (1024.0 * 1024.0),
				nbytes / (1024.0 * 1024.0 * 1024.0));

    exit(0);
}