- sprintf(ptr, "%s%s%08x%08x",dir,sep,lrand48(),lrand48());
+ unsigned int r1 = (unsigned int)lrand48();
+ unsigned int r2 = (unsigned int)lrand48();
+#elif HAVE_RAND
+ unsigned int r1 = rand();
+ unsigned int r2 = rand();
+#else
+ static int count = 1;
+ unsigned int r1 = time(0);
+ unsigned int r2 = (unsigned int)tmpbuf<<8^count;
+ count ++;
+#endif
+ if(ext) {
+ sprintf(ptr, "%s%s%04x%04x.%s",dir,sep,r1,r2,ext);
+ } else {
+ sprintf(ptr, "%s%s%04x%04x",dir,sep,r1,r2);
+ }
+ return ptr;
+}
+
+memfile_t* memfile_open(const char*path)
+{
+ memfile_t*file = malloc(sizeof(memfile_t));
+#if defined(HAVE_MMAP) && defined(HAVE_STAT)
+ int fi = open(path, O_RDONLY);
+ if(fi<0) {
+ perror(path);
+ free(file);
+ return 0;
+ }
+ struct stat sb;
+ if(fstat(fi, &sb)<0) {
+ perror(path);
+ return 0;
+ }
+ file->len = sb.st_size;
+ file->data = mmap(0, sb.st_size, PROT_READ, MAP_PRIVATE, fi, 0);