| 1 |
/* Licensed to the Apache Software Foundation (ASF) under one or more |
| 2 |
* contributor license agreements. See the NOTICE file distributed with |
| 3 |
* this work for additional information regarding copyright ownership. |
| 4 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
| 5 |
* (the "License"); you may not use this file except in compliance with |
| 6 |
* the License. You may obtain a copy of the License at |
| 7 |
* |
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
* |
| 10 |
* Unless required by applicable law or agreed to in writing, software |
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
* See the License for the specific language governing permissions and |
| 14 |
* limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include "apr_arch_file_io.h"cxx . . $ `<file>/include/arch/unix/apr_arch_file_io.h`/ |
| 18 |
|
| 19 |
#if APR_HAVE_FCNTL_Hcxx . . $ `include/apr.h:82:9`! |
| 20 |
#include <fcntl.h> |
| 21 |
#endif |
| 22 |
#ifdef HAVE_SYS_FILE_Hcxx . . $ `include/arch/unix/apr_private.h:631:9`! |
| 23 |
#include <sys/file.h> |
| 24 |
#endif |
| 25 |
|
| 26 |
APR_DECLAREcxx . . $ `include/apr.h:507:9`!(apr_status_t) apr_file_lockcxx . . $ apr_file_lock(53860f4344c8384e).(apr_file_tcxx . . $ apr_file_t# *thefile, int type) |
| 27 |
{ |
| 28 |
int rc; |
| 29 |
|
| •30 |
#if 0 && defined(HAVE_FCNTL_Hcxx . . $ `include/arch/unix/apr_private.h:178:9`!) |
| 31 |
{ |
| 32 |
struct flock l = { 0 }; |
| 33 |
int fc; |
| 34 |
|
| 35 |
l.l_whence = SEEK_SET; /* count l_start from start of file */ |
| 36 |
l.l_start = 0; /* lock from start of file */ |
| 37 |
l.l_len = 0; /* lock to end of file */ |
| 38 |
if ((type & APR_FLOCK_TYPEMASK) == APR_FLOCK_SHARED) |
| 39 |
l.l_type = F_RDLCK; |
| 40 |
else |
| 41 |
l.l_type = F_WRLCK; |
| 42 |
|
| 43 |
fc = (type & APR_FLOCK_NONBLOCK) ? F_SETLK : F_SETLKW; |
| 44 |
|
| 45 |
/* keep trying if fcntl() gets interrupted (by a signal) */ |
| 46 |
while ((rc = fcntl(thefile->filedes, fc, &l)) < 0 && errno == EINTR) |
| 47 |
continue; |
| 48 |
|
| 49 |
if (rc == -1) { |
| 50 |
/* on some Unix boxes (e.g., Tru64), we get EACCES instead |
| 51 |
* of EAGAIN; we don't want APR_STATUS_IS_EAGAIN() matching EACCES |
| 52 |
* since that breaks other things, so fix up the retcode here |
| 53 |
*/ |
| 54 |
if (errno == EACCES) { |
| 55 |
return EAGAIN; |
| 56 |
} |
| 57 |
return errno; |
| 58 |
} |
| 59 |
} |
| 60 |
#elif defined(HAVE_SYS_FILE_Hcxx . . $ `include/arch/unix/apr_private.h:631:9`!) |
| 61 |
{ |
| 62 |
int ltype; |
| 63 |
|
| 64 |
if ((type & APR_FLOCK_TYPEMASKcxx . . $ `include/apr_file_io.h:207:9`!) == APR_FLOCK_SHAREDcxx . . $ `include/apr_file_io.h:196:9`!) |
| 65 |
ltype = LOCK_SHcxx . . $ `<external>/8566841665215861632/file.h:40:9`!; |
| 66 |
else |
| 67 |
ltype = LOCK_EXcxx . . $ `<external>/8566841665215861632/file.h:41:9`!; |
| 68 |
if ((type & APR_FLOCK_NONBLOCKcxx . . $ `include/apr_file_io.h:208:9`!) != 0) |
| 69 |
ltype |= LOCK_NBcxx . . $ `<external>/8566841665215861632/file.h:45:9`!; |
| 70 |
|
| 71 |
/* keep trying if flock() gets interrupted (by a signal) */ |
| 72 |
while ((rc = flockcxx . . $ flock(9b79fb6aee4c0440).(thefile->filedescxx . . $ apr_file_t#filedes., ltype)) < 0 && errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!) |
| 73 |
continue; |
| 74 |
|
| 75 |
if (rc == -1) |
| 76 |
return errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!; |
| 77 |
} |
| 78 |
#else |
| 79 |
#error No file locking mechanism is available. |
| 80 |
#endif |
| 81 |
|
| 82 |
return APR_SUCCESScxx . . $ `include/apr_errno.h:225:9`!; |
| 83 |
} |
| 84 |
|
| 85 |
APR_DECLAREcxx . . $ `include/apr.h:507:9`!(apr_status_t) apr_file_unlockcxx . . $ apr_file_unlock(ac1f877fcad40383).(apr_file_tcxx . . $ apr_file_t# *thefile) |
| 86 |
{ |
| 87 |
int rc; |
| 88 |
|
| •89 |
#if 0 && defined(HAVE_FCNTL_Hcxx . . $ `include/arch/unix/apr_private.h:178:9`!) |
| 90 |
{ |
| 91 |
struct flock l = { 0 }; |
| 92 |
|
| 93 |
l.l_whence = SEEK_SET; /* count l_start from start of file */ |
| 94 |
l.l_start = 0; /* lock from start of file */ |
| 95 |
l.l_len = 0; /* lock to end of file */ |
| 96 |
l.l_type = F_UNLCK; |
| 97 |
|
| 98 |
/* keep trying if fcntl() gets interrupted (by a signal) */ |
| 99 |
while ((rc = fcntl(thefile->filedes, F_SETLKW, &l)) < 0 |
| 100 |
&& errno == EINTR) |
| 101 |
continue; |
| 102 |
|
| 103 |
if (rc == -1) |
| 104 |
return errno; |
| 105 |
} |
| 106 |
#elif defined(HAVE_SYS_FILE_Hcxx . . $ `include/arch/unix/apr_private.h:631:9`!) |
| 107 |
{ |
| 108 |
/* keep trying if flock() gets interrupted (by a signal) */ |
| 109 |
while ((rc = flockcxx . . $ flock(9b79fb6aee4c0440).(thefile->filedescxx . . $ apr_file_t#filedes., LOCK_UNcxx . . $ `<external>/8566841665215861632/file.h:42:9`!)) < 0 && errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!) |
| 110 |
continue; |
| 111 |
|
| 112 |
if (rc == -1) |
| 113 |
return errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!; |
| 114 |
} |
| 115 |
#else |
| 116 |
#error No file locking mechanism is available. |
| 117 |
#endif |
| 118 |
|
| 119 |
return APR_SUCCESScxx . . $ `include/apr_errno.h:225:9`!; |
| 120 |
} |