Reduce differences with root_skels in contrib.
[dragonfly.git] / contrib / bsdinstaller-1.1.6 / ports / www / thttpd-notimeout / files / patch-mmc.c
blobc992a32508449666c9f55cfa46e3a40e4cb90722
1 --- mmc.c.orig Tue Oct 22 09:42:01 2002
2 +++ mmc.c Fri Nov 14 12:26:39 2003
3 @@ -74,6 +74,9 @@
4 time_t ctime;
5 int refcount;
6 time_t reftime;
7 +#ifdef USE_SENDFILE
8 + int fd;
9 +#endif
10 void* addr;
11 unsigned int hash;
12 int hash_idx;
13 @@ -140,7 +143,11 @@
14 /* Yep. Just return the existing map */
15 ++m->refcount;
16 m->reftime = now;
17 +#ifdef USE_SENDFILE
18 + return (&m->fd);
19 +#else
20 return m->addr;
21 +#endif
24 /* Open the file. */
25 @@ -186,7 +193,9 @@
26 else
28 size_t size_size = (size_t) m->size; /* loses on files >2GB */
29 -#ifdef HAVE_MMAP
30 +#ifdef USE_SENDFILE
31 + m->fd = fd;
32 +#elif defined(HAVE_MMAP)
33 /* Map the file into memory. */
34 m->addr = mmap( 0, size_size, PROT_READ, MAP_PRIVATE, fd, 0 );
35 if ( m->addr == (void*) -1 && errno == ENOMEM )
36 @@ -234,8 +243,9 @@
38 #endif /* HAVE_MMAP */
40 +#ifndef USE_SENDFILE
41 (void) close( fd );
43 +#endif /* !USE_SENDFILE */
44 /* Put the Map into the hash table. */
45 if ( add_hash( m ) < 0 )
47 @@ -253,8 +263,12 @@
48 /* Update the total byte count. */
49 mapped_bytes += m->size;
51 +#ifdef USE_SENDFILE
52 + return (&m->fd);
53 +#else
54 /* And return the address. */
55 return m->addr;
56 +#endif
60 @@ -267,14 +281,18 @@
61 if ( sbP != (struct stat*) 0 )
63 m = find_hash( sbP->st_ino, sbP->st_dev, sbP->st_size, sbP->st_ctime );
64 +#ifndef USE_SENDFILE
65 if ( m != (Map*) 0 && m->addr != addr )
66 m = (Map*) 0;
67 +#endif
69 +#ifndef USE_SENDFILE
70 /* If that didn't work, try a full search. */
71 if ( m == (Map*) 0 )
72 for ( m = maps; m != (Map*) 0; m = m->next )
73 if ( m->addr == addr )
74 break;
75 +#endif
76 if ( m == (Map*) 0 )
77 syslog( LOG_ERR, "mmc_unmap failed to find entry!" );
78 else if ( m->refcount <= 0 )
79 @@ -363,7 +381,9 @@
80 m = *mm;
81 if ( m->size != 0 )
83 -#ifdef HAVE_MMAP
84 +#ifdef USE_SENDFILE
85 + close(m->fd);
86 +#elif defined(HAVE_MMAP)
87 if ( munmap( m->addr, m->size ) < 0 )
88 syslog( LOG_ERR, "munmap - %m" );
89 #else /* HAVE_MMAP */