Mercurial > hg > nginx
comparison src/os/unix/ngx_files.c @ 3651:515d50917016
ngx_create_file_mapping()
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 29 Jun 2010 15:18:50 +0000 |
parents | e19df6e65352 |
children | fbd7dad43a4e |
comparison
equal
deleted
inserted
replaced
3650:c12b0dd5bd1c | 3651:515d50917016 |
---|---|
257 return NGX_ERROR; | 257 return NGX_ERROR; |
258 } | 258 } |
259 | 259 |
260 | 260 |
261 ngx_int_t | 261 ngx_int_t |
262 ngx_create_file_mapping(ngx_file_mapping_t *fm) | |
263 { | |
264 fm->fd = ngx_open_file(fm->name, NGX_FILE_RDWR, NGX_FILE_TRUNCATE, | |
265 NGX_FILE_DEFAULT_ACCESS); | |
266 if (fm->fd == NGX_INVALID_FILE) { | |
267 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
268 ngx_open_file_n " \"%s\" failed", fm->name); | |
269 return NGX_ERROR; | |
270 } | |
271 | |
272 if (ftruncate(fm->fd, fm->size) == -1) { | |
273 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
274 "ftruncate() \"%s\" failed", fm->name); | |
275 goto failed; | |
276 } | |
277 | |
278 fm->addr = mmap(NULL, fm->size, PROT_READ|PROT_WRITE, MAP_SHARED, | |
279 fm->fd, 0); | |
280 if (fm->addr != MAP_FAILED) { | |
281 return NGX_OK; | |
282 } | |
283 | |
284 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
285 "mmap(%uz) \"%s\" failed", fm->size, fm->name); | |
286 | |
287 failed: | |
288 | |
289 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) { | |
290 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
291 ngx_close_file_n " \"%s\" failed", fm->name); | |
292 } | |
293 | |
294 return NGX_ERROR; | |
295 } | |
296 | |
297 | |
298 void | |
299 ngx_close_file_mapping(ngx_file_mapping_t *fm) | |
300 { | |
301 if (munmap(fm->addr, fm->size) == -1) { | |
302 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
303 "munmap(%uz) \"%s\" failed", fm->size, fm->name); | |
304 } | |
305 | |
306 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) { | |
307 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
308 ngx_close_file_n " \"%s\" failed", fm->name); | |
309 } | |
310 } | |
311 | |
312 | |
313 ngx_int_t | |
262 ngx_open_dir(ngx_str_t *name, ngx_dir_t *dir) | 314 ngx_open_dir(ngx_str_t *name, ngx_dir_t *dir) |
263 { | 315 { |
264 dir->dir = opendir((const char *) name->data); | 316 dir->dir = opendir((const char *) name->data); |
265 | 317 |
266 if (dir->dir == NULL) { | 318 if (dir->dir == NULL) { |