Apache HTTPD
flock.c
Go to the documentation of this file.
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"
18
20{
21#ifdef _WIN32_WCE
22 /* The File locking is unsuported on WCE */
23 return APR_ENOTIMPL;
24#else
25 const DWORD len = 0xffffffff;
26 DWORD flags;
27
31 if (apr_os_level >= APR_WIN_NT) {
32 /* Syntax is correct, len is passed for LengthLow and LengthHigh*/
34 memset (&offset, 0, sizeof(offset));
36 return apr_get_os_error();
37 }
38 else {
39 /* On Win9x, LockFile() never blocks. Hack in a crufty poll.
40 *
41 * Note that this hack exposes threads to being unserviced forever,
42 * in the situation that the given lock has low availability.
43 * When implemented in the kernel, LockFile will typically use
44 * FIFO or round robin distribution to ensure all threads get
45 * one crack at the lock; but in this case we can't emulate that.
46 *
47 * However Win9x are barely maintainable anyways, if the user does
48 * choose to build to them, this is the best we can do.
49 */
50 while (!LockFile(thefile->filehand, 0, 0, len, 0)) {
53 {
54 Sleep(500); /* pause for a half second */
55 continue; /* ... and then poll again */
56 }
57 return APR_FROM_OS_ERROR(err);
58 }
59 }
60
61 return APR_SUCCESS;
62#endif /* !defined(_WIN32_WCE) */
63}
64
66{
67#ifdef _WIN32_WCE
68 return APR_ENOTIMPL;
69#else
70 DWORD len = 0xffffffff;
71
72 if (apr_os_level >= APR_WIN_NT) {
73 /* Syntax is correct, len is passed for LengthLow and LengthHigh*/
75 memset (&offset, 0, sizeof(offset));
77 return apr_get_os_error();
78 }
79 else {
80 if (!UnlockFile(thefile->filehand, 0, 0, len, 0))
81 return apr_get_os_error();
82 }
83
84 return APR_SUCCESS;
85#endif /* !defined(_WIN32_WCE) */
86}
const char apr_size_t len
Definition ap_regex.h:187
#define APR_ENOTIMPL
Definition apr_errno.h:476
const char apr_ssize_t int flags
Definition apr_encode.h:168
const void apr_status_t(*) apr_status_t(* APR_DECLARE)(void) apr_pool_pre_cleanup_register(apr_pool_t *p
Definition apr_pools.h:646
apr_size_t size
#define APR_FROM_OS_ERROR(e)
Definition apr_errno.h:1214
#define APR_SUCCESS
Definition apr_errno.h:225
#define apr_get_os_error()
Definition apr_errno.h:1217
int apr_status_t
Definition apr_errno.h:44
apr_file_t * thefile
apr_seek_where_t apr_off_t * offset
int type
#define APR_FLOCK_TYPEMASK
#define APR_FLOCK_NONBLOCK
#define APR_FLOCK_SHARED
apr_int32_t apr_int32_t apr_int32_t err
apr_status_t apr_file_lock(apr_file_t *thefile, int type)
Definition flock.c:21
apr_status_t apr_file_unlock(apr_file_t *thefile)
Definition flock.c:33
APR_DECLARE_DATA apr_oslevel_e apr_os_level
Definition misc.c:24
@ APR_WIN_NT
typedef DWORD(WINAPI *apr_winapi_fpt_GetCompressedFileSizeA)(IN LPCSTR lpFileName