Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib/mmap-util.c @ 1000:0fbafade2d85 HEAD
If auth/login process died unexpectedly, the exit status or killing signal
wasn't logged.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 21 Jan 2003 09:58:49 +0200 |
parents | 52fd3d82e59a |
children | be6749ad05ad |
rev | line source |
---|---|
0 | 1 /* |
2 mmap-util.c - Memory mapping utilities | |
3 | |
4 Copyright (c) 2002 Timo Sirainen | |
5 | |
6 Permission is hereby granted, free of charge, to any person obtaining | |
7 a copy of this software and associated documentation files (the | |
8 "Software"), to deal in the Software without restriction, including | |
9 without limitation the rights to use, copy, modify, merge, publish, | |
10 distribute, sublicense, and/or sell copies of the Software, and to | |
11 permit persons to whom the Software is furnished to do so, subject to | |
12 the following conditions: | |
13 | |
14 The above copyright notice and this permission notice shall be | |
15 included in all copies or substantial portions of the Software. | |
16 | |
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
18 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
20 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | |
21 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | |
22 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
23 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
24 */ | |
25 | |
26 #include "lib.h" | |
27 #include "mmap-util.h" | |
28 | |
543
52fd3d82e59a
Removed mmap_aligned() which isn't used anywhere. Added mmap_file() which
Timo Sirainen <tss@iki.fi>
parents:
222
diff
changeset
|
29 #include <sys/stat.h> |
52fd3d82e59a
Removed mmap_aligned() which isn't used anywhere. Added mmap_file() which
Timo Sirainen <tss@iki.fi>
parents:
222
diff
changeset
|
30 |
52fd3d82e59a
Removed mmap_aligned() which isn't used anywhere. Added mmap_file() which
Timo Sirainen <tss@iki.fi>
parents:
222
diff
changeset
|
31 void *mmap_file(int fd, size_t *length, int prot) |
0 | 32 { |
543
52fd3d82e59a
Removed mmap_aligned() which isn't used anywhere. Added mmap_file() which
Timo Sirainen <tss@iki.fi>
parents:
222
diff
changeset
|
33 struct stat st; |
43
526284657da7
Fail if we try to mmap() files larger than 2G fully to memory
Timo Sirainen <tss@iki.fi>
parents:
6
diff
changeset
|
34 |
543
52fd3d82e59a
Removed mmap_aligned() which isn't used anywhere. Added mmap_file() which
Timo Sirainen <tss@iki.fi>
parents:
222
diff
changeset
|
35 if (fstat(fd, &st) < 0) |
0 | 36 return MAP_FAILED; |
37 | |
543
52fd3d82e59a
Removed mmap_aligned() which isn't used anywhere. Added mmap_file() which
Timo Sirainen <tss@iki.fi>
parents:
222
diff
changeset
|
38 if (st.st_size > SSIZE_T_MAX) { |
43
526284657da7
Fail if we try to mmap() files larger than 2G fully to memory
Timo Sirainen <tss@iki.fi>
parents:
6
diff
changeset
|
39 /* too large file to map into memory */ |
526284657da7
Fail if we try to mmap() files larger than 2G fully to memory
Timo Sirainen <tss@iki.fi>
parents:
6
diff
changeset
|
40 errno = EFBIG; |
526284657da7
Fail if we try to mmap() files larger than 2G fully to memory
Timo Sirainen <tss@iki.fi>
parents:
6
diff
changeset
|
41 return MAP_FAILED; |
526284657da7
Fail if we try to mmap() files larger than 2G fully to memory
Timo Sirainen <tss@iki.fi>
parents:
6
diff
changeset
|
42 } |
526284657da7
Fail if we try to mmap() files larger than 2G fully to memory
Timo Sirainen <tss@iki.fi>
parents:
6
diff
changeset
|
43 |
543
52fd3d82e59a
Removed mmap_aligned() which isn't used anywhere. Added mmap_file() which
Timo Sirainen <tss@iki.fi>
parents:
222
diff
changeset
|
44 *length = (size_t)st.st_size; |
0 | 45 if (*length == 0) |
46 return NULL; | |
47 | |
183
4a7ab9e94f25
size_t fixes for lib/. Changed OFF_T_FORMAT to PRIuOFF_T which is more
Timo Sirainen <tss@iki.fi>
parents:
43
diff
changeset
|
48 i_assert(*length > 0 && *length < SSIZE_T_MAX); |
0 | 49 |
543
52fd3d82e59a
Removed mmap_aligned() which isn't used anywhere. Added mmap_file() which
Timo Sirainen <tss@iki.fi>
parents:
222
diff
changeset
|
50 return mmap(NULL, *length, prot, MAP_SHARED, fd, 0); |
0 | 51 } |
52 | |
53 void *mmap_ro_file(int fd, size_t *length) | |
54 { | |
55 return mmap_file(fd, length, PROT_READ); | |
56 } | |
57 | |
58 void *mmap_rw_file(int fd, size_t *length) | |
59 { | |
60 return mmap_file(fd, length, PROT_READ | PROT_WRITE); | |
61 } | |
62 | |
63 #ifndef HAVE_MADVISE | |
64 int madvise(void *start, size_t length, int advice) | |
65 { | |
66 } | |
67 #endif |