/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1999-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* *18***********************************************************************/19#define mmap ___mmap20#define mmap64 ___mmap642122#include "sftest.h"2324#undef off_t25#undef mmap26#undef mmap642728/* This test causes mmap() to fail so that read() must be used.29On a system such as BSDI, malloc uses mmap() so if mmap()30fails, not much else will work. In such a case, we make this31test automatically success.32*/3334static int Success = 1;3536#if __STD_C37void* mmap(void* addr, size_t size, int x, int y, int z, off_t offset)38#else39void* mmap()40#endif41{42if(Success)43texit(0);4445return (void*)(-1);46}4748#if __STD_C49void* mmap64(void* addr, size_t size, int x, int y, int z, Sfoff_t offset)50#else51void* mmap64()52#endif53{54if(Success)55texit(0);5657return (void*)(-1);58}5960tmain()61{62Sfio_t* f;63char buf[1024], buf2[1024], *data;64int n, r;6566/* test to see if malloc() winds up calling mmap() */67if(!(data = (char*)malloc(8*1024)) )68terror("Malloc failed");69free(data);70Success = 0;7172/* our real work */73if(!(f = sfopen(NIL(Sfio_t*), tstfile("sf", 0),"w")) )74terror("Can't open to write");7576for(n = 0; n < sizeof(buf); ++n)77buf[n] = '0' + (n%10);7879for(n = 0; n < 10; ++n)80sfwrite(f,buf,sizeof(buf));8182if(!(f = sfopen(f, tstfile("sf", 0),"r")) )83terror("Can't open to read");8485for(n = 0; n < 10; ++n)86{ if((r = sfread(f,buf2,sizeof(buf))) != sizeof(buf))87terror("Bad read size=%d",r);88if(strncmp(buf,buf2,sizeof(buf)) != 0)89terror("Get wrong data");90}9192texit(0);93}949596