code
stringlengths
1
2.01M
repo_name
stringlengths
3
62
path
stringlengths
1
267
language
stringclasses
231 values
license
stringclasses
13 values
size
int64
1
2.01M
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "testutil.h" #include "apr_file_info.h" #include "apr_errno.h" #include "apr_pools.h" #include "apr_tables.h" #if defined(WIN32) || defined(NETWARE) || defined(OS2) #define PSEP ";" #define DSEP "\\" #else #define PSEP ":" #define DSEP "/" #endif #define PX "" #define P1 "first path" #define P2 "second" DSEP "path" #define P3 "th ird" DSEP "path" #define P4 "fourth" DSEP "pa th" #define P5 "fifthpath" static const char *parts_in[] = { P1, P2, P3, PX, P4, P5 }; static const char *path_in = P1 PSEP P2 PSEP P3 PSEP PX PSEP P4 PSEP P5; static const int parts_in_count = sizeof(parts_in)/sizeof(*parts_in); static const char *parts_out[] = { P1, P2, P3, P4, P5 }; static const char *path_out = P1 PSEP P2 PSEP P3 PSEP P4 PSEP P5; static const int parts_out_count = sizeof(parts_out)/sizeof(*parts_out); static void list_split_multi(abts_case *tc, void *data) { int i; apr_status_t rv; apr_array_header_t *pathelts; pathelts = NULL; rv = apr_filepath_list_split(&pathelts, path_in, p); ABTS_PTR_NOTNULL(tc, pathelts); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, parts_out_count, pathelts->nelts); for (i = 0; i < pathelts->nelts; ++i) ABTS_STR_EQUAL(tc, parts_out[i], ((char**)pathelts->elts)[i]); } static void list_split_single(abts_case *tc, void *data) { int i; apr_status_t rv; apr_array_header_t *pathelts; for (i = 0; i < parts_in_count; ++i) { pathelts = NULL; rv = apr_filepath_list_split(&pathelts, parts_in[i], p); ABTS_PTR_NOTNULL(tc, pathelts); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); if (parts_in[i][0] == '\0') ABTS_INT_EQUAL(tc, 0, pathelts->nelts); else { ABTS_INT_EQUAL(tc, 1, pathelts->nelts); ABTS_STR_EQUAL(tc, parts_in[i], *(char**)pathelts->elts); } } } static void list_merge_multi(abts_case *tc, void *data) { int i; char *liststr; apr_status_t rv; apr_array_header_t *pathelts; pathelts = apr_array_make(p, parts_in_count, sizeof(const char*)); for (i = 0; i < parts_in_count; ++i) *(const char**)apr_array_push(pathelts) = parts_in[i]; liststr = NULL; rv = apr_filepath_list_merge(&liststr, pathelts, p); ABTS_PTR_NOTNULL(tc, liststr); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_STR_EQUAL(tc, liststr, path_out); } static void list_merge_single(abts_case *tc, void *data) { int i; char *liststr; apr_status_t rv; apr_array_header_t *pathelts; pathelts = apr_array_make(p, 1, sizeof(const char*)); apr_array_push(pathelts); for (i = 0; i < parts_in_count; ++i) { *(const char**)pathelts->elts = parts_in[i]; liststr = NULL; rv = apr_filepath_list_merge(&liststr, pathelts, p); if (parts_in[i][0] == '\0') ABTS_PTR_EQUAL(tc, NULL, liststr); else { ABTS_PTR_NOTNULL(tc, liststr); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_STR_EQUAL(tc, liststr, parts_in[i]); } } } abts_suite *testpath(abts_suite *suite) { suite = ADD_SUITE(suite) abts_run_test(suite, list_split_multi, NULL); abts_run_test(suite, list_split_single, NULL); abts_run_test(suite, list_merge_multi, NULL); abts_run_test(suite, list_merge_single, NULL); return suite; }
001-log4cxx
trunk/src/apr/test/testpath.c
C
asf20
4,179
/* Copyright 2000-2004 Ryan Bloom * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifdef __cplusplus extern "C" { #endif #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #ifndef ABTS_H #define ABTS_H #ifndef FALSE #define FALSE 0 #endif #ifndef TRUE #define TRUE 1 #endif struct sub_suite { const char *name; int num_test; int failed; int not_run; int not_impl; struct sub_suite *next; }; typedef struct sub_suite sub_suite; struct abts_suite { sub_suite *head; sub_suite *tail; }; typedef struct abts_suite abts_suite; struct abts_case { int failed; sub_suite *suite; }; typedef struct abts_case abts_case; typedef void (*test_func)(abts_case *tc, void *data); #define ADD_SUITE(suite) abts_add_suite(suite, __FILE__); abts_suite *abts_add_suite(abts_suite *suite, const char *suite_name); void abts_run_test(abts_suite *ts, test_func f, void *value); void abts_log_message(const char *fmt, ...); void abts_int_equal(abts_case *tc, const int expected, const int actual, int lineno); void abts_int_nequal(abts_case *tc, const int expected, const int actual, int lineno); void abts_str_equal(abts_case *tc, const char *expected, const char *actual, int lineno); void abts_str_nequal(abts_case *tc, const char *expected, const char *actual, size_t n, int lineno); void abts_ptr_notnull(abts_case *tc, const void *ptr, int lineno); void abts_ptr_equal(abts_case *tc, const void *expected, const void *actual, int lineno); void abts_true(abts_case *tc, int condition, int lineno); void abts_fail(abts_case *tc, const char *message, int lineno); void abts_not_impl(abts_case *tc, const char *message, int lineno); void abts_assert(abts_case *tc, const char *message, int condition, int lineno); /* Convenience macros. Ryan hates these! */ #define ABTS_INT_EQUAL(a, b, c) abts_int_equal(a, b, c, __LINE__) #define ABTS_INT_NEQUAL(a, b, c) abts_int_nequal(a, b, c, __LINE__) #define ABTS_STR_EQUAL(a, b, c) abts_str_equal(a, b, c, __LINE__) #define ABTS_STR_NEQUAL(a, b, c, d) abts_str_nequal(a, b, c, d, __LINE__) #define ABTS_PTR_NOTNULL(a, b) abts_ptr_notnull(a, b, __LINE__) #define ABTS_PTR_EQUAL(a, b, c) abts_ptr_equal(a, b, c, __LINE__) #define ABTS_TRUE(a, b) abts_true(a, b, __LINE__); #define ABTS_FAIL(a, b) abts_fail(a, b, __LINE__); #define ABTS_NOT_IMPL(a, b) abts_not_impl(a, b, __LINE__); #define ABTS_ASSERT(a, b, c) abts_assert(a, b, c, __LINE__); abts_suite *run_tests(abts_suite *suite); abts_suite *run_tests1(abts_suite *suite); #endif #ifdef __cplusplus } #endif
001-log4cxx
trunk/src/apr/test/abts.h
C
asf20
3,164
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "testflock.h" #include "apr_pools.h" #include "apr_file_io.h" #include "apr_general.h" #include "apr.h" #if APR_HAVE_STDLIB_H #include <stdlib.h> #endif int main(int argc, const char * const *argv) { apr_file_t *file; apr_status_t status; apr_pool_t *p; apr_initialize(); apr_pool_create(&p, NULL); if (apr_file_open(&file, TESTFILE, APR_WRITE, APR_OS_DEFAULT, p) != APR_SUCCESS) { exit(UNEXPECTED_ERROR); } status = apr_file_lock(file, APR_FLOCK_EXCLUSIVE | APR_FLOCK_NONBLOCK); if (status == APR_SUCCESS) { exit(SUCCESSFUL_READ); } if (APR_STATUS_IS_EAGAIN(status)) { exit(FAILED_READ); } exit(UNEXPECTED_ERROR); }
001-log4cxx
trunk/src/apr/test/tryread.c
C
asf20
1,524
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "testutil.h" #include "apr_strings.h" #include "apr_errno.h" #include "apr_general.h" #include "apr_lib.h" #include "apr_network_io.h" #include "apr_poll.h" #define SMALL_NUM_SOCKETS 3 /* We can't use 64 here, because some platforms *ahem* Solaris *ahem* have * a default limit of 64 open file descriptors per process. If we use * 64, the test will fail even though the code is correct. */ #define LARGE_NUM_SOCKETS 50 static apr_socket_t *s[LARGE_NUM_SOCKETS]; static apr_sockaddr_t *sa[LARGE_NUM_SOCKETS]; static apr_pollset_t *pollset; /* ###: tests surrounded by ifdef OLD_POLL_INTERFACE either need to be * converted to use the pollset interface or removed. */ #ifdef OLD_POLL_INTERFACE static apr_pollfd_t *pollarray; static apr_pollfd_t *pollarray_large; #endif static void make_socket(apr_socket_t **sock, apr_sockaddr_t **sa, apr_port_t port, apr_pool_t *p, abts_case *tc) { apr_status_t rv; rv = apr_sockaddr_info_get(sa, "127.0.0.1", APR_UNSPEC, port, 0, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_socket_create(sock, (*sa)->family, SOCK_DGRAM, 0, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv =apr_socket_bind((*sock), (*sa)); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); } #ifdef OLD_POLL_INTERFACE static void check_sockets(const apr_pollfd_t *pollarray, apr_socket_t **sockarray, int which, int pollin, abts_case *tc) { apr_status_t rv; apr_int16_t event; char *str; rv = apr_poll_revents_get(&event, sockarray[which], (apr_pollfd_t *)pollarray); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); if (pollin) { str = apr_psprintf(p, "Socket %d not signalled when it should be", which); ABTS_ASSERT(tc, str, event & APR_POLLIN); } else { str = apr_psprintf(p, "Socket %d signalled when it should not be", which); ABTS_ASSERT(tc, str, !(event & APR_POLLIN)); } } #endif static void send_msg(apr_socket_t **sockarray, apr_sockaddr_t **sas, int which, abts_case *tc) { apr_size_t len = 5; apr_status_t rv; ABTS_PTR_NOTNULL(tc, sockarray[which]); rv = apr_socket_sendto(sockarray[which], sas[which], 0, "hello", &len); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, strlen("hello"), len); } static void recv_msg(apr_socket_t **sockarray, int which, apr_pool_t *p, abts_case *tc) { apr_size_t buflen = 5; char *buffer = apr_pcalloc(p, sizeof(char) * (buflen + 1)); apr_sockaddr_t *recsa; apr_status_t rv; ABTS_PTR_NOTNULL(tc, sockarray[which]); apr_sockaddr_info_get(&recsa, "127.0.0.1", APR_UNSPEC, 7770, 0, p); rv = apr_socket_recvfrom(recsa, sockarray[which], 0, buffer, &buflen); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, strlen("hello"), buflen); ABTS_STR_EQUAL(tc, "hello", buffer); } static void create_all_sockets(abts_case *tc, void *data) { int i; for (i = 0; i < LARGE_NUM_SOCKETS; i++){ make_socket(&s[i], &sa[i], 7777 + i, p, tc); } } #ifdef OLD_POLL_INTERFACE static void setup_small_poll(abts_case *tc, void *data) { apr_status_t rv; int i; rv = apr_poll_setup(&pollarray, SMALL_NUM_SOCKETS, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); for (i = 0; i < SMALL_NUM_SOCKETS;i++){ ABTS_INT_EQUAL(tc, 0, pollarray[i].reqevents); ABTS_INT_EQUAL(tc, 0, pollarray[i].rtnevents); rv = apr_poll_socket_add(pollarray, s[i], APR_POLLIN); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_PTR_EQUAL(tc, s[i], pollarray[i].desc.s); } } static void setup_large_poll(abts_case *tc, void *data) { apr_status_t rv; int i; rv = apr_poll_setup(&pollarray_large, LARGE_NUM_SOCKETS, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); for (i = 0; i < LARGE_NUM_SOCKETS;i++){ ABTS_INT_EQUAL(tc, 0, pollarray_large[i].reqevents); ABTS_INT_EQUAL(tc, 0, pollarray_large[i].rtnevents); rv = apr_poll_socket_add(pollarray_large, s[i], APR_POLLIN); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_PTR_EQUAL(tc, s[i], pollarray_large[i].desc.s); } } static void nomessage(abts_case *tc, void *data) { apr_status_t rv; int srv = SMALL_NUM_SOCKETS; rv = apr_poll(pollarray, SMALL_NUM_SOCKETS, &srv, 2 * APR_USEC_PER_SEC); ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv)); check_sockets(pollarray, s, 0, 0, tc); check_sockets(pollarray, s, 1, 0, tc); check_sockets(pollarray, s, 2, 0, tc); } static void send_2(abts_case *tc, void *data) { apr_status_t rv; int srv = SMALL_NUM_SOCKETS; send_msg(s, sa, 2, tc); rv = apr_poll(pollarray, SMALL_NUM_SOCKETS, &srv, 2 * APR_USEC_PER_SEC); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); check_sockets(pollarray, s, 0, 0, tc); check_sockets(pollarray, s, 1, 0, tc); check_sockets(pollarray, s, 2, 1, tc); } static void recv_2_send_1(abts_case *tc, void *data) { apr_status_t rv; int srv = SMALL_NUM_SOCKETS; recv_msg(s, 2, p, tc); send_msg(s, sa, 1, tc); rv = apr_poll(pollarray, SMALL_NUM_SOCKETS, &srv, 2 * APR_USEC_PER_SEC); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); check_sockets(pollarray, s, 0, 0, tc); check_sockets(pollarray, s, 1, 1, tc); check_sockets(pollarray, s, 2, 0, tc); } static void send_2_signaled_1(abts_case *tc, void *data) { apr_status_t rv; int srv = SMALL_NUM_SOCKETS; send_msg(s, sa, 2, tc); rv = apr_poll(pollarray, SMALL_NUM_SOCKETS, &srv, 2 * APR_USEC_PER_SEC); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); check_sockets(pollarray, s, 0, 0, tc); check_sockets(pollarray, s, 1, 1, tc); check_sockets(pollarray, s, 2, 1, tc); } static void recv_1_send_0(abts_case *tc, void *data) { apr_status_t rv; int srv = SMALL_NUM_SOCKETS; recv_msg(s, 1, p, tc); send_msg(s, sa, 0, tc); rv = apr_poll(pollarray, SMALL_NUM_SOCKETS, &srv, 2 * APR_USEC_PER_SEC); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); check_sockets(pollarray, s, 0, 1, tc); check_sockets(pollarray, s, 1, 0, tc); check_sockets(pollarray, s, 2, 1, tc); } static void clear_all_signalled(abts_case *tc, void *data) { apr_status_t rv; int srv = SMALL_NUM_SOCKETS; recv_msg(s, 0, p, tc); recv_msg(s, 2, p, tc); rv = apr_poll(pollarray, SMALL_NUM_SOCKETS, &srv, 2 * APR_USEC_PER_SEC); ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv)); check_sockets(pollarray, s, 0, 0, tc); check_sockets(pollarray, s, 1, 0, tc); check_sockets(pollarray, s, 2, 0, tc); } static void send_large_pollarray(abts_case *tc, void *data) { apr_status_t rv; int lrv = LARGE_NUM_SOCKETS; int i; send_msg(s, sa, LARGE_NUM_SOCKETS - 1, tc); rv = apr_poll(pollarray_large, LARGE_NUM_SOCKETS, &lrv, 2 * APR_USEC_PER_SEC); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); for (i = 0; i < LARGE_NUM_SOCKETS; i++) { if (i == (LARGE_NUM_SOCKETS - 1)) { check_sockets(pollarray_large, s, i, 1, tc); } else { check_sockets(pollarray_large, s, i, 0, tc); } } } static void recv_large_pollarray(abts_case *tc, void *data) { apr_status_t rv; int lrv = LARGE_NUM_SOCKETS; int i; recv_msg(s, LARGE_NUM_SOCKETS - 1, p, tc); rv = apr_poll(pollarray_large, LARGE_NUM_SOCKETS, &lrv, 2 * APR_USEC_PER_SEC); ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv)); for (i = 0; i < LARGE_NUM_SOCKETS; i++) { check_sockets(pollarray_large, s, i, 0, tc); } } #endif static void setup_pollset(abts_case *tc, void *data) { apr_status_t rv; rv = apr_pollset_create(&pollset, LARGE_NUM_SOCKETS, p, 0); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); } static void multi_event_pollset(abts_case *tc, void *data) { apr_status_t rv; apr_pollfd_t socket_pollfd; int lrv; const apr_pollfd_t *descs = NULL; ABTS_PTR_NOTNULL(tc, s[0]); socket_pollfd.desc_type = APR_POLL_SOCKET; socket_pollfd.reqevents = APR_POLLIN | APR_POLLOUT; socket_pollfd.desc.s = s[0]; socket_pollfd.client_data = s[0]; rv = apr_pollset_add(pollset, &socket_pollfd); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); send_msg(s, sa, 0, tc); rv = apr_pollset_poll(pollset, 0, &lrv, &descs); ABTS_INT_EQUAL(tc, 0, APR_STATUS_IS_TIMEUP(rv)); if (lrv == 1) { ABTS_PTR_EQUAL(tc, s[0], descs[0].desc.s); ABTS_INT_EQUAL(tc, APR_POLLIN | APR_POLLOUT, descs[0].rtnevents); ABTS_PTR_EQUAL(tc, s[0], descs[0].client_data); } else if (lrv == 2) { ABTS_PTR_EQUAL(tc, s[0], descs[0].desc.s); ABTS_PTR_EQUAL(tc, s[0], descs[0].client_data); ABTS_PTR_EQUAL(tc, s[0], descs[1].desc.s); ABTS_PTR_EQUAL(tc, s[0], descs[1].client_data); ABTS_ASSERT(tc, "returned events incorrect", ((descs[0].rtnevents | descs[1].rtnevents) == (APR_POLLIN | APR_POLLOUT)) && descs[0].rtnevents != descs[1].rtnevents); } else { ABTS_ASSERT(tc, "either one or two events returned", lrv == 1 || lrv == 2); } recv_msg(s, 0, p, tc); rv = apr_pollset_poll(pollset, 0, &lrv, &descs); ABTS_INT_EQUAL(tc, 0, APR_STATUS_IS_TIMEUP(rv)); ABTS_INT_EQUAL(tc, 1, lrv); ABTS_PTR_EQUAL(tc, s[0], descs[0].desc.s); ABTS_INT_EQUAL(tc, APR_POLLOUT, descs[0].rtnevents); ABTS_PTR_EQUAL(tc, s[0], descs[0].client_data); rv = apr_pollset_remove(pollset, &socket_pollfd); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); } static void add_sockets_pollset(abts_case *tc, void *data) { apr_status_t rv; int i; for (i = 0; i < LARGE_NUM_SOCKETS;i++){ apr_pollfd_t socket_pollfd; ABTS_PTR_NOTNULL(tc, s[i]); socket_pollfd.desc_type = APR_POLL_SOCKET; socket_pollfd.reqevents = APR_POLLIN; socket_pollfd.desc.s = s[i]; socket_pollfd.client_data = s[i]; rv = apr_pollset_add(pollset, &socket_pollfd); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); } } static void nomessage_pollset(abts_case *tc, void *data) { apr_status_t rv; int lrv; const apr_pollfd_t *descs = NULL; rv = apr_pollset_poll(pollset, 0, &lrv, &descs); ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv)); ABTS_INT_EQUAL(tc, 0, lrv); ABTS_PTR_EQUAL(tc, NULL, descs); } static void send0_pollset(abts_case *tc, void *data) { apr_status_t rv; const apr_pollfd_t *descs = NULL; int num; send_msg(s, sa, 0, tc); rv = apr_pollset_poll(pollset, 0, &num, &descs); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, 1, num); ABTS_PTR_NOTNULL(tc, descs); ABTS_PTR_EQUAL(tc, s[0], descs[0].desc.s); ABTS_PTR_EQUAL(tc, s[0], descs[0].client_data); } static void recv0_pollset(abts_case *tc, void *data) { apr_status_t rv; int lrv; const apr_pollfd_t *descs = NULL; recv_msg(s, 0, p, tc); rv = apr_pollset_poll(pollset, 0, &lrv, &descs); ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv)); ABTS_INT_EQUAL(tc, 0, lrv); ABTS_PTR_EQUAL(tc, NULL, descs); } static void send_middle_pollset(abts_case *tc, void *data) { apr_status_t rv; const apr_pollfd_t *descs = NULL; int num; send_msg(s, sa, 2, tc); send_msg(s, sa, 5, tc); rv = apr_pollset_poll(pollset, 0, &num, &descs); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, 2, num); ABTS_PTR_NOTNULL(tc, descs); ABTS_ASSERT(tc, "Incorrect socket in result set", ((descs[0].desc.s == s[2]) && (descs[1].desc.s == s[5])) || ((descs[0].desc.s == s[5]) && (descs[1].desc.s == s[2]))); } static void clear_middle_pollset(abts_case *tc, void *data) { apr_status_t rv; int lrv; const apr_pollfd_t *descs = NULL; recv_msg(s, 2, p, tc); recv_msg(s, 5, p, tc); rv = apr_pollset_poll(pollset, 0, &lrv, &descs); ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv)); ABTS_INT_EQUAL(tc, 0, lrv); ABTS_PTR_EQUAL(tc, NULL, descs); } static void send_last_pollset(abts_case *tc, void *data) { apr_status_t rv; const apr_pollfd_t *descs = NULL; int num; send_msg(s, sa, LARGE_NUM_SOCKETS - 1, tc); rv = apr_pollset_poll(pollset, 0, &num, &descs); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, 1, num); ABTS_PTR_NOTNULL(tc, descs); ABTS_PTR_EQUAL(tc, s[LARGE_NUM_SOCKETS - 1], descs[0].desc.s); ABTS_PTR_EQUAL(tc, s[LARGE_NUM_SOCKETS - 1], descs[0].client_data); } static void clear_last_pollset(abts_case *tc, void *data) { apr_status_t rv; int lrv; const apr_pollfd_t *descs = NULL; recv_msg(s, LARGE_NUM_SOCKETS - 1, p, tc); rv = apr_pollset_poll(pollset, 0, &lrv, &descs); ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv)); ABTS_INT_EQUAL(tc, 0, lrv); ABTS_PTR_EQUAL(tc, NULL, descs); } static void close_all_sockets(abts_case *tc, void *data) { apr_status_t rv; int i; for (i = 0; i < LARGE_NUM_SOCKETS; i++){ rv = apr_socket_close(s[i]); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); } } static void pollset_remove(abts_case *tc, void *data) { apr_status_t rv; apr_pollset_t *pollset; const apr_pollfd_t *hot_files; apr_pollfd_t pfd; apr_int32_t num; rv = apr_pollset_create(&pollset, 5, p, 0); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); pfd.p = p; pfd.desc_type = APR_POLL_SOCKET; pfd.reqevents = APR_POLLOUT; pfd.desc.s = s[0]; pfd.client_data = (void *)1; rv = apr_pollset_add(pollset, &pfd); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); pfd.desc.s = s[1]; pfd.client_data = (void *)2; rv = apr_pollset_add(pollset, &pfd); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); pfd.desc.s = s[2]; pfd.client_data = (void *)3; rv = apr_pollset_add(pollset, &pfd); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); pfd.desc.s = s[3]; pfd.client_data = (void *)4; rv = apr_pollset_add(pollset, &pfd); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_pollset_poll(pollset, 1000, &num, &hot_files); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, 4, num); /* now remove the pollset element referring to desc s[1] */ pfd.desc.s = s[1]; pfd.client_data = (void *)999; /* not used on this call */ rv = apr_pollset_remove(pollset, &pfd); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); /* this time only three should match */ rv = apr_pollset_poll(pollset, 1000, &num, &hot_files); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, 3, num); ABTS_PTR_EQUAL(tc, (void *)1, hot_files[0].client_data); ABTS_PTR_EQUAL(tc, s[0], hot_files[0].desc.s); ABTS_PTR_EQUAL(tc, (void *)3, hot_files[1].client_data); ABTS_PTR_EQUAL(tc, s[2], hot_files[1].desc.s); ABTS_PTR_EQUAL(tc, (void *)4, hot_files[2].client_data); ABTS_PTR_EQUAL(tc, s[3], hot_files[2].desc.s); /* now remove the pollset elements referring to desc s[2] */ pfd.desc.s = s[2]; pfd.client_data = (void *)999; /* not used on this call */ rv = apr_pollset_remove(pollset, &pfd); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); /* this time only two should match */ rv = apr_pollset_poll(pollset, 1000, &num, &hot_files); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, 2, num); ABTS_ASSERT(tc, "Incorrect socket in result set", ((hot_files[0].desc.s == s[0]) && (hot_files[1].desc.s == s[3])) || ((hot_files[0].desc.s == s[3]) && (hot_files[1].desc.s == s[0]))); ABTS_ASSERT(tc, "Incorrect client data in result set", ((hot_files[0].client_data == (void *)1) && (hot_files[1].client_data == (void *)4)) || ((hot_files[0].client_data == (void *)4) && (hot_files[1].client_data == (void *)1))); } abts_suite *testpoll(abts_suite *suite) { suite = ADD_SUITE(suite) abts_run_test(suite, create_all_sockets, NULL); #ifdef OLD_POLL_INTERFACE abts_run_test(suite, setup_small_poll, NULL); abts_run_test(suite, setup_large_poll, NULL); abts_run_test(suite, nomessage, NULL); abts_run_test(suite, send_2, NULL); abts_run_test(suite, recv_2_send_1, NULL); abts_run_test(suite, send_2_signaled_1, NULL); abts_run_test(suite, recv_1_send_0, NULL); abts_run_test(suite, clear_all_signalled, NULL); abts_run_test(suite, send_large_pollarray, NULL); abts_run_test(suite, recv_large_pollarray, NULL); #endif abts_run_test(suite, setup_pollset, NULL); abts_run_test(suite, multi_event_pollset, NULL); abts_run_test(suite, add_sockets_pollset, NULL); abts_run_test(suite, nomessage_pollset, NULL); abts_run_test(suite, send0_pollset, NULL); abts_run_test(suite, recv0_pollset, NULL); abts_run_test(suite, send_middle_pollset, NULL); abts_run_test(suite, clear_middle_pollset, NULL); abts_run_test(suite, send_last_pollset, NULL); abts_run_test(suite, clear_last_pollset, NULL); abts_run_test(suite, pollset_remove, NULL); abts_run_test(suite, close_all_sockets, NULL); return suite; }
001-log4cxx
trunk/src/apr/test/testpoll.c
C
asf20
18,118
#include "apr.h" #include "apr_file_io.h" #include "apr.h" #if APR_HAVE_STDLIB_H #include <stdlib.h> #endif int main(void) { char buf[256]; apr_file_t *err; apr_pool_t *p; apr_initialize(); atexit(apr_terminate); apr_pool_create(&p, NULL); apr_file_open_stdin(&err, p); while (1) { apr_size_t length = 256; apr_file_read(err, buf, &length); } exit(0); /* just to keep the compiler happy */ }
001-log4cxx
trunk/src/apr/test/occhild.c
C
asf20
453
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "apr_file_io.h" #include "apr_file_info.h" #include "apr_strings.h" #include "apr_errno.h" #include "apr_general.h" #include "apr_poll.h" #include "apr_lib.h" #include "testutil.h" #define FILENAME "data/file_datafile.txt" #define NEWFILENAME "data/new_datafile.txt" #define NEWFILEDATA "This is new text in a new file." static const struct view_fileinfo { apr_int32_t bits; char *description; } vfi[] = { {APR_FINFO_MTIME, "MTIME"}, {APR_FINFO_CTIME, "CTIME"}, {APR_FINFO_ATIME, "ATIME"}, {APR_FINFO_SIZE, "SIZE"}, {APR_FINFO_DEV, "DEV"}, {APR_FINFO_INODE, "INODE"}, {APR_FINFO_NLINK, "NLINK"}, {APR_FINFO_TYPE, "TYPE"}, {APR_FINFO_USER, "USER"}, {APR_FINFO_GROUP, "GROUP"}, {APR_FINFO_UPROT, "UPROT"}, {APR_FINFO_GPROT, "GPROT"}, {APR_FINFO_WPROT, "WPROT"}, {0, NULL} }; static void finfo_equal(abts_case *tc, apr_finfo_t *f1, apr_finfo_t *f2) { /* Minimum supported flags across all platforms (APR_FINFO_MIN) */ ABTS_ASSERT(tc, "apr_stat and apr_getfileinfo must return APR_FINFO_TYPE", (f1->valid & f2->valid & APR_FINFO_TYPE)); ABTS_ASSERT(tc, "apr_stat and apr_getfileinfo differ in filetype", f1->filetype == f2->filetype); ABTS_ASSERT(tc, "apr_stat and apr_getfileinfo must return APR_FINFO_SIZE", (f1->valid & f2->valid & APR_FINFO_SIZE)); ABTS_ASSERT(tc, "apr_stat and apr_getfileinfo differ in size", f1->size == f2->size); ABTS_ASSERT(tc, "apr_stat and apr_getfileinfo must return APR_FINFO_ATIME", (f1->valid & f2->valid & APR_FINFO_ATIME)); ABTS_ASSERT(tc, "apr_stat and apr_getfileinfo differ in atime", f1->atime == f2->atime); ABTS_ASSERT(tc, "apr_stat and apr_getfileinfo must return APR_FINFO_MTIME", (f1->valid & f2->valid & APR_FINFO_MTIME)); ABTS_ASSERT(tc, "apr_stat and apr_getfileinfo differ in mtime", f1->mtime == f2->mtime); ABTS_ASSERT(tc, "apr_stat and apr_getfileinfo must return APR_FINFO_CTIME", (f1->valid & f2->valid & APR_FINFO_CTIME)); ABTS_ASSERT(tc, "apr_stat and apr_getfileinfo differ in ctime", f1->ctime == f2->ctime); if (f1->valid & f2->valid & APR_FINFO_NAME) ABTS_ASSERT(tc, "apr_stat and apr_getfileinfo differ in name", !strcmp(f1->name, f2->name)); if (f1->fname && f2->fname) ABTS_ASSERT(tc, "apr_stat and apr_getfileinfo differ in fname", !strcmp(f1->fname, f2->fname)); /* Additional supported flags not supported on all platforms */ if (f1->valid & f2->valid & APR_FINFO_USER) ABTS_ASSERT(tc, "apr_stat and apr_getfileinfo differ in user", !apr_uid_compare(f1->user, f2->user)); if (f1->valid & f2->valid & APR_FINFO_GROUP) ABTS_ASSERT(tc, "apr_stat and apr_getfileinfo differ in group", !apr_gid_compare(f1->group, f2->group)); if (f1->valid & f2->valid & APR_FINFO_INODE) ABTS_ASSERT(tc, "apr_stat and apr_getfileinfo differ in inode", f1->inode == f2->inode); if (f1->valid & f2->valid & APR_FINFO_DEV) ABTS_ASSERT(tc, "apr_stat and apr_getfileinfo differ in device", f1->device == f2->device); if (f1->valid & f2->valid & APR_FINFO_NLINK) ABTS_ASSERT(tc, "apr_stat and apr_getfileinfo differ in nlink", f1->nlink == f2->nlink); if (f1->valid & f2->valid & APR_FINFO_CSIZE) ABTS_ASSERT(tc, "apr_stat and apr_getfileinfo differ in csize", f1->csize == f2->csize); if (f1->valid & f2->valid & APR_FINFO_PROT) ABTS_ASSERT(tc, "apr_stat and apr_getfileinfo differ in protection", f1->protection == f2->protection); } static void test_info_get(abts_case *tc, void *data) { apr_file_t *thefile; apr_finfo_t finfo; apr_status_t rv; rv = apr_file_open(&thefile, FILENAME, APR_READ, APR_OS_DEFAULT, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_file_info_get(&finfo, APR_FINFO_NORM, thefile); if (rv == APR_INCOMPLETE) { char *str; int i; str = apr_pstrdup(p, "APR_INCOMPLETE: Missing "); for (i = 0; vfi[i].bits; ++i) { if (vfi[i].bits & ~finfo.valid) { str = apr_pstrcat(p, str, vfi[i].description, " ", NULL); } } ABTS_FAIL(tc, str); } ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); apr_file_close(thefile); } static void test_stat(abts_case *tc, void *data) { apr_finfo_t finfo; apr_status_t rv; rv = apr_stat(&finfo, FILENAME, APR_FINFO_NORM, p); if (rv == APR_INCOMPLETE) { char *str; int i; str = apr_pstrdup(p, "APR_INCOMPLETE: Missing "); for (i = 0; vfi[i].bits; ++i) { if (vfi[i].bits & ~finfo.valid) { str = apr_pstrcat(p, str, vfi[i].description, " ", NULL); } } ABTS_FAIL(tc, str); } ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); } static void test_stat_eq_finfo(abts_case *tc, void *data) { apr_file_t *thefile; apr_finfo_t finfo; apr_finfo_t stat_finfo; apr_status_t rv; rv = apr_file_open(&thefile, FILENAME, APR_READ, APR_OS_DEFAULT, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_file_info_get(&finfo, APR_FINFO_NORM, thefile); /* Opening the file may have toggled the atime member (time last * accessed), so fetch our apr_stat() after getting the fileinfo * of the open file... */ rv = apr_stat(&stat_finfo, FILENAME, APR_FINFO_NORM, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); apr_file_close(thefile); finfo_equal(tc, &stat_finfo, &finfo); } static void test_buffered_write_size(abts_case *tc, void *data) { const apr_size_t data_len = strlen(NEWFILEDATA); apr_file_t *thefile; apr_finfo_t finfo; apr_status_t rv; apr_size_t bytes; rv = apr_file_open(&thefile, NEWFILENAME, APR_READ | APR_WRITE | APR_CREATE | APR_TRUNCATE | APR_BUFFERED | APR_DELONCLOSE, APR_OS_DEFAULT, p); APR_ASSERT_SUCCESS(tc, "open file", rv); /* A funny thing happened to me the other day: I wrote something * into a buffered file, then asked for its size using * apr_file_info_get; and guess what? The size was 0! That's not a * nice way to behave. */ bytes = data_len; rv = apr_file_write(thefile, NEWFILEDATA, &bytes); APR_ASSERT_SUCCESS(tc, "write file contents", rv); ABTS_TRUE(tc, data_len == bytes); rv = apr_file_info_get(&finfo, APR_FINFO_SIZE, thefile); APR_ASSERT_SUCCESS(tc, "get file size", rv); ABTS_TRUE(tc, bytes == (apr_size_t) finfo.size); apr_file_close(thefile); } static void test_mtime_set(abts_case *tc, void *data) { apr_file_t *thefile; apr_finfo_t finfo; apr_time_t epoch = 0; apr_status_t rv; /* This test sort of depends on the system clock being at least * marginally ccorrect; We'll be setting the modification time to * the epoch. */ rv = apr_file_open(&thefile, NEWFILENAME, APR_READ | APR_WRITE | APR_CREATE | APR_TRUNCATE | APR_BUFFERED | APR_DELONCLOSE, APR_OS_DEFAULT, p); APR_ASSERT_SUCCESS(tc, "open file", rv); /* Check that the current mtime is not the epoch */ rv = apr_stat(&finfo, NEWFILENAME, APR_FINFO_MTIME, p); if (rv == APR_INCOMPLETE) { char *str; int i; str = apr_pstrdup(p, "APR_INCOMPLETE: Missing "); for (i = 0; vfi[i].bits; ++i) { if (vfi[i].bits & ~finfo.valid) { str = apr_pstrcat(p, str, vfi[i].description, " ", NULL); } } ABTS_FAIL(tc, str); } APR_ASSERT_SUCCESS(tc, "get initial mtime", rv); ABTS_TRUE(tc, finfo.mtime != epoch); /* Reset the mtime to the epoch and verify the result. * Note: we blindly assume that if the first apr_stat succeeded, * the second one will, too. */ rv = apr_file_mtime_set(NEWFILENAME, epoch, p); APR_ASSERT_SUCCESS(tc, "set mtime", rv); rv = apr_stat(&finfo, NEWFILENAME, APR_FINFO_MTIME, p); APR_ASSERT_SUCCESS(tc, "get modified mtime", rv); ABTS_TRUE(tc, finfo.mtime == epoch); apr_file_close(thefile); } abts_suite *testfileinfo(abts_suite *suite) { suite = ADD_SUITE(suite) abts_run_test(suite, test_info_get, NULL); abts_run_test(suite, test_stat, NULL); abts_run_test(suite, test_stat_eq_finfo, NULL); abts_run_test(suite, test_buffered_write_size, NULL); abts_run_test(suite, test_mtime_set, NULL); return suite; }
001-log4cxx
trunk/src/apr/test/testfileinfo.c
C
asf20
9,557
#include <apr.h> #include <apr_general.h> int main(int argc, const char * const * argv, const char * const *env) { apr_app_initialize(&argc, &argv, &env); apr_terminate(); }
001-log4cxx
trunk/src/apr/test/testapp.c
C
asf20
185
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "apr_env.h" #include "apr_errno.h" #include "testutil.h" #define TEST_ENVVAR_NAME "apr_test_envvar" #define TEST_ENVVAR2_NAME "apr_test_envvar2" #define TEST_ENVVAR_VALUE "Just a value that we'll check" static int have_env_set; static int have_env_get; static int have_env_del; static void test_setenv(abts_case *tc, void *data) { apr_status_t rv; rv = apr_env_set(TEST_ENVVAR_NAME, TEST_ENVVAR_VALUE, p); have_env_set = (rv != APR_ENOTIMPL); if (!have_env_set) { ABTS_NOT_IMPL(tc, "apr_env_set"); } else { APR_ASSERT_SUCCESS(tc, "set environment variable", rv); } } static void test_getenv(abts_case *tc, void *data) { char *value; apr_status_t rv; if (!have_env_set) { ABTS_NOT_IMPL(tc, "apr_env_set (skip test for apr_env_get)"); return; } rv = apr_env_get(&value, TEST_ENVVAR_NAME, p); have_env_get = (rv != APR_ENOTIMPL); if (!have_env_get) { ABTS_NOT_IMPL(tc, "apr_env_get"); return; } APR_ASSERT_SUCCESS(tc, "get environment variable", rv); ABTS_STR_EQUAL(tc, TEST_ENVVAR_VALUE, value); } static void test_delenv(abts_case *tc, void *data) { char *value; apr_status_t rv; if (!have_env_set) { ABTS_NOT_IMPL(tc, "apr_env_set (skip test for apr_env_delete)"); return; } rv = apr_env_delete(TEST_ENVVAR_NAME, p); have_env_del = (rv != APR_ENOTIMPL); if (!have_env_del) { ABTS_NOT_IMPL(tc, "apr_env_delete"); return; } APR_ASSERT_SUCCESS(tc, "delete environment variable", rv); if (!have_env_get) { ABTS_NOT_IMPL(tc, "apr_env_get (skip sanity check for apr_env_delete)"); return; } rv = apr_env_get(&value, TEST_ENVVAR_NAME, p); ABTS_INT_EQUAL(tc, APR_ENOENT, rv); } /** http://issues.apache.org/bugzilla/show_bug.cgi?id=40764 */ static void test_emptyenv(abts_case *tc, void *data) { char *value; apr_status_t rv; if (!(have_env_set && have_env_get)) { ABTS_NOT_IMPL(tc, "apr_env_set (skip test_emptyenv)"); return; } /** Set empty string and test that rv != ENOENT) */ rv = apr_env_set(TEST_ENVVAR_NAME, "", p); APR_ASSERT_SUCCESS(tc, "set environment variable", rv); rv = apr_env_get(&value, TEST_ENVVAR_NAME, p); APR_ASSERT_SUCCESS(tc, "get environment variable", rv); ABTS_STR_EQUAL(tc, "", value); if (!have_env_del) { ABTS_NOT_IMPL(tc, "apr_env_del (skip recycle test_emptyenv)"); return; } /** Delete and retest */ rv = apr_env_delete(TEST_ENVVAR_NAME, p); APR_ASSERT_SUCCESS(tc, "delete environment variable", rv); rv = apr_env_get(&value, TEST_ENVVAR_NAME, p); ABTS_INT_EQUAL(tc, APR_ENOENT, rv); /** Set second variable + test*/ rv = apr_env_set(TEST_ENVVAR2_NAME, TEST_ENVVAR_VALUE, p); APR_ASSERT_SUCCESS(tc, "set second environment variable", rv); rv = apr_env_get(&value, TEST_ENVVAR2_NAME, p); APR_ASSERT_SUCCESS(tc, "get second environment variable", rv); ABTS_STR_EQUAL(tc, TEST_ENVVAR_VALUE, value); /** Finally, test ENOENT (first variable) followed by second != ENOENT) */ rv = apr_env_get(&value, TEST_ENVVAR_NAME, p); ABTS_INT_EQUAL(tc, APR_ENOENT, rv); rv = apr_env_get(&value, TEST_ENVVAR2_NAME, p); APR_ASSERT_SUCCESS(tc, "verify second environment variable", rv); ABTS_STR_EQUAL(tc, TEST_ENVVAR_VALUE, value); /** Cleanup */ apr_env_delete(TEST_ENVVAR2_NAME, p); } abts_suite *testenv(abts_suite *suite) { suite = ADD_SUITE(suite) abts_run_test(suite, test_setenv, NULL); abts_run_test(suite, test_getenv, NULL); abts_run_test(suite, test_delenv, NULL); abts_run_test(suite, test_emptyenv, NULL); return suite; }
001-log4cxx
trunk/src/apr/test/testenv.c
C
asf20
4,565
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "apr_shm.h" #include "apr_thread_proc.h" #include "apr_file_io.h" #include "apr_proc_mutex.h" #include "apr_errno.h" #include "apr_general.h" #include "apr_getopt.h" #include "errno.h" #include <stdio.h> #include <stdlib.h> #include "testutil.h" #if APR_HAS_FORK #define MAX_ITER 200 #define CHILDREN 6 #define MAX_COUNTER (MAX_ITER * CHILDREN) static apr_proc_mutex_t *proc_lock; static volatile int *x; /* a slower more racy way to implement (*x)++ */ static int increment(int n) { apr_sleep(1); return n+1; } static void make_child(abts_case *tc, apr_proc_t **proc, apr_pool_t *p) { apr_status_t rv; *proc = apr_pcalloc(p, sizeof(**proc)); /* slight delay to allow things to settle */ apr_sleep (1); rv = apr_proc_fork(*proc, p); if (rv == APR_INCHILD) { int i = 0; /* The parent process has setup all processes to call apr_terminate * at exit. But, that means that all processes must also call * apr_initialize at startup. You cannot have an unequal number * of apr_terminate and apr_initialize calls. If you do, bad things * will happen. In this case, the bad thing is that if the mutex * is a semaphore, it will be destroyed before all of the processes * die. That means that the test will most likely fail. */ apr_initialize(); if (apr_proc_mutex_child_init(&proc_lock, NULL, p)) exit(1); do { if (apr_proc_mutex_lock(proc_lock)) exit(1); i++; *x = increment(*x); if (apr_proc_mutex_unlock(proc_lock)) exit(1); } while (i < MAX_ITER); exit(0); } ABTS_ASSERT(tc, "fork failed", rv == APR_INPARENT); } /* Wait for a child process and check it terminated with success. */ static void await_child(abts_case *tc, apr_proc_t *proc) { int code; apr_exit_why_e why; apr_status_t rv; rv = apr_proc_wait(proc, &code, &why, APR_WAIT); ABTS_ASSERT(tc, "child did not terminate with success", rv == APR_CHILD_DONE && why == APR_PROC_EXIT && code == 0); } static void test_exclusive(abts_case *tc, const char *lockname, apr_lockmech_e mech) { apr_proc_t *child[CHILDREN]; apr_status_t rv; int n; rv = apr_proc_mutex_create(&proc_lock, lockname, mech, p); APR_ASSERT_SUCCESS(tc, "create the mutex", rv); if (rv != APR_SUCCESS) return; for (n = 0; n < CHILDREN; n++) make_child(tc, &child[n], p); for (n = 0; n < CHILDREN; n++) await_child(tc, child[n]); ABTS_ASSERT(tc, "Locks don't appear to work", *x == MAX_COUNTER); } #endif static void proc_mutex(abts_case *tc, void *data) { #if APR_HAS_FORK apr_status_t rv; const char *shmname = "tpm.shm"; apr_shm_t *shm; apr_lockmech_e *mech = data; /* Use anonymous shm if available. */ rv = apr_shm_create(&shm, sizeof(int), NULL, p); if (rv == APR_ENOTIMPL) { apr_file_remove(shmname, p); rv = apr_shm_create(&shm, sizeof(int), shmname, p); } APR_ASSERT_SUCCESS(tc, "create shm segment", rv); if (rv != APR_SUCCESS) return; x = apr_shm_baseaddr_get(shm); test_exclusive(tc, NULL, *mech); rv = apr_shm_destroy(shm); APR_ASSERT_SUCCESS(tc, "Error destroying shared memory block", rv); #else ABTS_NOT_IMPL(tc, "APR lacks fork() support"); #endif } abts_suite *testprocmutex(abts_suite *suite) { apr_lockmech_e mech = APR_LOCK_DEFAULT; suite = ADD_SUITE(suite) abts_run_test(suite, proc_mutex, &mech); #if APR_HAS_POSIXSEM_SERIALIZE mech = APR_LOCK_POSIXSEM; abts_run_test(suite, proc_mutex, &mech); #endif #if APR_HAS_SYSVSEM_SERIALIZE mech = APR_LOCK_SYSVSEM; abts_run_test(suite, proc_mutex, &mech); #endif #if APR_HAS_PROC_PTHREAD_SERIALIZE mech = APR_LOCK_PROC_PTHREAD; abts_run_test(suite, proc_mutex, &mech); #endif #if APR_HAS_FCNTL_SERIALIZE mech = APR_LOCK_FCNTL; abts_run_test(suite, proc_mutex, &mech); #endif #if APR_HAS_FLOCK_SERIALIZE mech = APR_LOCK_FLOCK; abts_run_test(suite, proc_mutex, &mech); #endif return suite; }
001-log4cxx
trunk/src/apr/test/testprocmutex.c
C
asf20
5,030
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <stdio.h> #include "testutil.h" #include "apr_version.h" #include "apr_general.h" static void test_strings(abts_case *tc, void *data) { ABTS_STR_EQUAL(tc, APR_VERSION_STRING, apr_version_string()); } #ifdef APR_IS_DEV_VERSION # define IS_DEV 1 #else # define IS_DEV 0 #endif static void test_ints(abts_case *tc, void *data) { apr_version_t vsn; apr_version(&vsn); ABTS_INT_EQUAL(tc, APR_MAJOR_VERSION, vsn.major); ABTS_INT_EQUAL(tc, APR_MINOR_VERSION, vsn.minor); ABTS_INT_EQUAL(tc, APR_PATCH_VERSION, vsn.patch); ABTS_INT_EQUAL(tc, IS_DEV, vsn.is_dev); } abts_suite *testvsn(abts_suite *suite) { suite = ADD_SUITE(suite) abts_run_test(suite, test_strings, NULL); abts_run_test(suite, test_ints, NULL); return suite; }
001-log4cxx
trunk/src/apr/test/testvsn.c
C
asf20
1,594
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "testutil.h" #include "testsock.h" #include "apr_thread_proc.h" #include "apr_network_io.h" #include "apr_errno.h" #include "apr_general.h" #include "apr_lib.h" #include "apr_strings.h" #include "apr_poll.h" static void launch_child(abts_case *tc, apr_proc_t *proc, const char *arg1, apr_pool_t *p) { apr_procattr_t *procattr; const char *args[3]; apr_status_t rv; rv = apr_procattr_create(&procattr, p); APR_ASSERT_SUCCESS(tc, "Couldn't create procattr", rv); rv = apr_procattr_io_set(procattr, APR_NO_PIPE, APR_NO_PIPE, APR_NO_PIPE); APR_ASSERT_SUCCESS(tc, "Couldn't set io in procattr", rv); rv = apr_procattr_error_check_set(procattr, 1); APR_ASSERT_SUCCESS(tc, "Couldn't set error check in procattr", rv); args[0] = "sockchild" EXTENSION; args[1] = arg1; args[2] = NULL; rv = apr_proc_create(proc, "./sockchild" EXTENSION, args, NULL, procattr, p); APR_ASSERT_SUCCESS(tc, "Couldn't launch program", rv); } static int wait_child(abts_case *tc, apr_proc_t *proc) { int exitcode; apr_exit_why_e why; ABTS_ASSERT(tc, "Error waiting for child process", apr_proc_wait(proc, &exitcode, &why, APR_WAIT) == APR_CHILD_DONE); ABTS_ASSERT(tc, "child terminated normally", why == APR_PROC_EXIT); return exitcode; } static void test_addr_info(abts_case *tc, void *data) { apr_status_t rv; apr_sockaddr_t *sa; rv = apr_sockaddr_info_get(&sa, NULL, APR_UNSPEC, 80, 0, p); APR_ASSERT_SUCCESS(tc, "Problem generating sockaddr", rv); rv = apr_sockaddr_info_get(&sa, "127.0.0.1", APR_UNSPEC, 80, 0, p); APR_ASSERT_SUCCESS(tc, "Problem generating sockaddr", rv); ABTS_STR_EQUAL(tc, "127.0.0.1", sa->hostname); } static apr_socket_t *setup_socket(abts_case *tc) { apr_status_t rv; apr_sockaddr_t *sa; apr_socket_t *sock; rv = apr_sockaddr_info_get(&sa, "127.0.0.1", APR_INET, 8021, 0, p); APR_ASSERT_SUCCESS(tc, "Problem generating sockaddr", rv); rv = apr_socket_create(&sock, sa->family, SOCK_STREAM, APR_PROTO_TCP, p); APR_ASSERT_SUCCESS(tc, "Problem creating socket", rv); rv = apr_socket_opt_set(sock, APR_SO_REUSEADDR, 1); APR_ASSERT_SUCCESS(tc, "Could not set REUSEADDR on socket", rv); rv = apr_socket_bind(sock, sa); APR_ASSERT_SUCCESS(tc, "Problem binding to port", rv); if (rv) return NULL; rv = apr_socket_listen(sock, 5); APR_ASSERT_SUCCESS(tc, "Problem listening on socket", rv); return sock; } static void test_create_bind_listen(abts_case *tc, void *data) { apr_status_t rv; apr_socket_t *sock = setup_socket(tc); if (!sock) return; rv = apr_socket_close(sock); APR_ASSERT_SUCCESS(tc, "Problem closing socket", rv); } static void test_send(abts_case *tc, void *data) { apr_status_t rv; apr_socket_t *sock; apr_socket_t *sock2; apr_proc_t proc; int protocol; apr_size_t length; sock = setup_socket(tc); if (!sock) return; launch_child(tc, &proc, "read", p); rv = apr_socket_accept(&sock2, sock, p); APR_ASSERT_SUCCESS(tc, "Problem with receiving connection", rv); apr_socket_protocol_get(sock2, &protocol); ABTS_INT_EQUAL(tc, APR_PROTO_TCP, protocol); length = strlen(DATASTR); apr_socket_send(sock2, DATASTR, &length); /* Make sure that the client received the data we sent */ ABTS_INT_EQUAL(tc, strlen(DATASTR), wait_child(tc, &proc)); rv = apr_socket_close(sock2); APR_ASSERT_SUCCESS(tc, "Problem closing connected socket", rv); rv = apr_socket_close(sock); APR_ASSERT_SUCCESS(tc, "Problem closing socket", rv); } static void test_recv(abts_case *tc, void *data) { apr_status_t rv; apr_socket_t *sock; apr_socket_t *sock2; apr_proc_t proc; int protocol; apr_size_t length = STRLEN; char datastr[STRLEN]; sock = setup_socket(tc); if (!sock) return; launch_child(tc, &proc, "write", p); rv = apr_socket_accept(&sock2, sock, p); APR_ASSERT_SUCCESS(tc, "Problem with receiving connection", rv); apr_socket_protocol_get(sock2, &protocol); ABTS_INT_EQUAL(tc, APR_PROTO_TCP, protocol); memset(datastr, 0, STRLEN); apr_socket_recv(sock2, datastr, &length); /* Make sure that the server received the data we sent */ ABTS_STR_EQUAL(tc, DATASTR, datastr); ABTS_INT_EQUAL(tc, strlen(datastr), wait_child(tc, &proc)); rv = apr_socket_close(sock2); APR_ASSERT_SUCCESS(tc, "Problem closing connected socket", rv); rv = apr_socket_close(sock); APR_ASSERT_SUCCESS(tc, "Problem closing socket", rv); } static void test_timeout(abts_case *tc, void *data) { apr_status_t rv; apr_socket_t *sock; apr_socket_t *sock2; apr_proc_t proc; int protocol; int exit; sock = setup_socket(tc); if (!sock) return; launch_child(tc, &proc, "read", p); rv = apr_socket_accept(&sock2, sock, p); APR_ASSERT_SUCCESS(tc, "Problem with receiving connection", rv); apr_socket_protocol_get(sock2, &protocol); ABTS_INT_EQUAL(tc, APR_PROTO_TCP, protocol); exit = wait_child(tc, &proc); ABTS_INT_EQUAL(tc, SOCKET_TIMEOUT, exit); /* We didn't write any data, so make sure the child program returns * an error. */ rv = apr_socket_close(sock2); APR_ASSERT_SUCCESS(tc, "Problem closing connected socket", rv); rv = apr_socket_close(sock); APR_ASSERT_SUCCESS(tc, "Problem closing socket", rv); } static void test_get_addr(abts_case *tc, void *data) { apr_status_t rv; apr_socket_t *ld, *sd, *cd; apr_sockaddr_t *sa, *ca; char a[128], b[128]; ld = setup_socket(tc); APR_ASSERT_SUCCESS(tc, "get local address of bound socket", apr_socket_addr_get(&sa, APR_LOCAL, ld)); rv = apr_socket_create(&cd, sa->family, SOCK_STREAM, APR_PROTO_TCP, p); APR_ASSERT_SUCCESS(tc, "create client socket", rv); APR_ASSERT_SUCCESS(tc, "enable non-block mode", apr_socket_opt_set(cd, APR_SO_NONBLOCK, 1)); /* It is valid for a connect() on a socket with NONBLOCK set to * succeed (if the connection can be established synchronously), * but if it does, this test cannot proceed. */ rv = apr_socket_connect(cd, sa); if (rv == APR_SUCCESS) { apr_socket_close(ld); apr_socket_close(cd); ABTS_NOT_IMPL(tc, "Cannot test if connect completes " "synchronously"); return; } if (!APR_STATUS_IS_EINPROGRESS(rv)) { apr_socket_close(ld); apr_socket_close(cd); APR_ASSERT_SUCCESS(tc, "connect to listener", rv); return; } APR_ASSERT_SUCCESS(tc, "accept connection", apr_socket_accept(&sd, ld, p)); { /* wait for writability */ apr_pollfd_t pfd; int n; pfd.p = p; pfd.desc_type = APR_POLL_SOCKET; pfd.reqevents = APR_POLLOUT|APR_POLLHUP; pfd.desc.s = cd; pfd.client_data = NULL; APR_ASSERT_SUCCESS(tc, "poll for connect completion", apr_poll(&pfd, 1, &n, 5 * APR_USEC_PER_SEC)); } APR_ASSERT_SUCCESS(tc, "get local address of server socket", apr_socket_addr_get(&sa, APR_LOCAL, sd)); APR_ASSERT_SUCCESS(tc, "get remote address of client socket", apr_socket_addr_get(&ca, APR_REMOTE, cd)); apr_snprintf(a, sizeof(a), "%pI", sa); apr_snprintf(b, sizeof(b), "%pI", ca); ABTS_STR_EQUAL(tc, a, b); apr_socket_close(cd); apr_socket_close(sd); apr_socket_close(ld); } abts_suite *testsock(abts_suite *suite) { suite = ADD_SUITE(suite) abts_run_test(suite, test_addr_info, NULL); abts_run_test(suite, test_create_bind_listen, NULL); abts_run_test(suite, test_send, NULL); abts_run_test(suite, test_recv, NULL); abts_run_test(suite, test_timeout, NULL); abts_run_test(suite, test_get_addr, NULL); return suite; }
001-log4cxx
trunk/src/apr/test/testsock.c
C
asf20
8,983
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef TESTSHM_H #define TESTSHM_H typedef struct mbox { char msg[1024]; int msgavail; } mbox; mbox *boxes; #define N_BOXES 10 #define SHARED_SIZE (apr_size_t)(N_BOXES * sizeof(mbox)) #define SHARED_FILENAME "data/apr.testshm.shm" #define N_MESSAGES 100 #define MSG "Sending a message" #endif
001-log4cxx
trunk/src/apr/test/testshm.h
C
asf20
1,108
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "testutil.h" #include "apr_general.h" #include "apr_pools.h" #include "apr_errno.h" #include "apr_dso.h" #include "apr_strings.h" #include "apr_file_info.h" #include "apr.h" #if APR_HAVE_UNISTD_H #include <unistd.h> #endif #if APR_HAS_DSO #ifdef NETWARE # define MOD_NAME "mod_test.nlm" #elif defined(BEOS) # define MOD_NAME "mod_test.so" #elif defined(WIN32) # define MOD_NAME "mod_test.dll" #elif defined(DARWIN) # define MOD_NAME ".libs/mod_test.so" # define LIB_NAME ".libs/libmod_test.dylib" #elif defined(__hpux__) || defined(__hpux) # define MOD_NAME ".libs/mod_test.sl" # define LIB_NAME ".libs/libmod_test.sl" #elif defined(_AIX) || defined(__bsdi__) # define MOD_NAME ".libs/libmod_test.so" # define LIB_NAME ".libs/libmod_test.so" #else /* Every other Unix */ # define MOD_NAME ".libs/mod_test.so" # define LIB_NAME ".libs/libmod_test.so" #endif static char *modname; static void test_load_module(abts_case *tc, void *data) { apr_dso_handle_t *h = NULL; apr_status_t status; char errstr[256]; status = apr_dso_load(&h, modname, p); ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); ABTS_PTR_NOTNULL(tc, h); apr_dso_unload(h); } static void test_dso_sym(abts_case *tc, void *data) { apr_dso_handle_t *h = NULL; apr_dso_handle_sym_t func1 = NULL; apr_status_t status; void (*function)(char str[256]); char teststr[256]; char errstr[256]; status = apr_dso_load(&h, modname, p); ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); ABTS_PTR_NOTNULL(tc, h); status = apr_dso_sym(&func1, h, "print_hello"); ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); ABTS_PTR_NOTNULL(tc, func1); if (!tc->failed) { function = (void (*)(char *))func1; (*function)(teststr); ABTS_STR_EQUAL(tc, "Hello - I'm a DSO!\n", teststr); } apr_dso_unload(h); } static void test_dso_sym_return_value(abts_case *tc, void *data) { apr_dso_handle_t *h = NULL; apr_dso_handle_sym_t func1 = NULL; apr_status_t status; int (*function)(int); char errstr[256]; status = apr_dso_load(&h, modname, p); ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); ABTS_PTR_NOTNULL(tc, h); status = apr_dso_sym(&func1, h, "count_reps"); ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); ABTS_PTR_NOTNULL(tc, func1); if (!tc->failed) { function = (int (*)(int))func1; status = (*function)(5); ABTS_INT_EQUAL(tc, 5, status); } apr_dso_unload(h); } static void test_unload_module(abts_case *tc, void *data) { apr_dso_handle_t *h = NULL; apr_status_t status; char errstr[256]; apr_dso_handle_sym_t func1 = NULL; status = apr_dso_load(&h, modname, p); ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); ABTS_PTR_NOTNULL(tc, h); status = apr_dso_unload(h); ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); status = apr_dso_sym(&func1, h, "print_hello"); ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_ESYMNOTFOUND(status)); } #ifdef LIB_NAME static char *libname; static void test_load_library(abts_case *tc, void *data) { apr_dso_handle_t *h = NULL; apr_status_t status; char errstr[256]; status = apr_dso_load(&h, libname, p); ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); ABTS_PTR_NOTNULL(tc, h); apr_dso_unload(h); } static void test_dso_sym_library(abts_case *tc, void *data) { apr_dso_handle_t *h = NULL; apr_dso_handle_sym_t func1 = NULL; apr_status_t status; void (*function)(char str[256]); char teststr[256]; char errstr[256]; status = apr_dso_load(&h, libname, p); ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); ABTS_PTR_NOTNULL(tc, h); status = apr_dso_sym(&func1, h, "print_hello"); ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); ABTS_PTR_NOTNULL(tc, func1); if (!tc->failed) { function = (void (*)(char *))func1; (*function)(teststr); ABTS_STR_EQUAL(tc, "Hello - I'm a DSO!\n", teststr); } apr_dso_unload(h); } static void test_dso_sym_return_value_library(abts_case *tc, void *data) { apr_dso_handle_t *h = NULL; apr_dso_handle_sym_t func1 = NULL; apr_status_t status; int (*function)(int); char errstr[256]; status = apr_dso_load(&h, libname, p); ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); ABTS_PTR_NOTNULL(tc, h); status = apr_dso_sym(&func1, h, "count_reps"); ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); ABTS_PTR_NOTNULL(tc, func1); if (!tc->failed) { function = (int (*)(int))func1; status = (*function)(5); ABTS_INT_EQUAL(tc, 5, status); } apr_dso_unload(h); } static void test_unload_library(abts_case *tc, void *data) { apr_dso_handle_t *h = NULL; apr_status_t status; char errstr[256]; apr_dso_handle_sym_t func1 = NULL; status = apr_dso_load(&h, libname, p); ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); ABTS_PTR_NOTNULL(tc, h); status = apr_dso_unload(h); ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); status = apr_dso_sym(&func1, h, "print_hello"); ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_ESYMNOTFOUND(status)); } #endif /* def(LIB_NAME) */ static void test_load_notthere(abts_case *tc, void *data) { apr_dso_handle_t *h = NULL; apr_status_t status; status = apr_dso_load(&h, "No_File.so", p); ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_EDSOOPEN(status)); ABTS_PTR_NOTNULL(tc, h); } #endif /* APR_HAS_DSO */ abts_suite *testdso(abts_suite *suite) { suite = ADD_SUITE(suite) #if APR_HAS_DSO apr_filepath_merge(&modname, NULL, MOD_NAME, 0, p); abts_run_test(suite, test_load_module, NULL); abts_run_test(suite, test_dso_sym, NULL); abts_run_test(suite, test_dso_sym_return_value, NULL); abts_run_test(suite, test_unload_module, NULL); #ifdef LIB_NAME apr_filepath_merge(&libname, NULL, LIB_NAME, 0, p); abts_run_test(suite, test_load_library, NULL); abts_run_test(suite, test_dso_sym_library, NULL); abts_run_test(suite, test_dso_sym_return_value_library, NULL); abts_run_test(suite, test_unload_library, NULL); #endif abts_run_test(suite, test_load_notthere, NULL); #endif /* APR_HAS_DSO */ return suite; }
001-log4cxx
trunk/src/apr/test/testdso.c
C
asf20
7,406
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "testutil.h" #include "apr_file_info.h" #include "apr_fnmatch.h" #include "apr_tables.h" /* XXX NUM_FILES must be equal to the nummber of expected files with a * .txt extension in the data directory at the time testfnmatch * happens to be run (!?!). */ #define NUM_FILES (5) static void test_glob(abts_case *tc, void *data) { int i; char **list; apr_array_header_t *result; APR_ASSERT_SUCCESS(tc, "glob match against data/*.txt", apr_match_glob("data\\*.txt", &result, p)); ABTS_INT_EQUAL(tc, NUM_FILES, result->nelts); list = (char **)result->elts; for (i = 0; i < result->nelts; i++) { char *dot = strrchr(list[i], '.'); ABTS_STR_EQUAL(tc, dot, ".txt"); } } static void test_glob_currdir(abts_case *tc, void *data) { int i; char **list; apr_array_header_t *result; apr_filepath_set("data", p); APR_ASSERT_SUCCESS(tc, "glob match against *.txt with data as current", apr_match_glob("*.txt", &result, p)); ABTS_INT_EQUAL(tc, NUM_FILES, result->nelts); list = (char **)result->elts; for (i = 0; i < result->nelts; i++) { char *dot = strrchr(list[i], '.'); ABTS_STR_EQUAL(tc, dot, ".txt"); } apr_filepath_set("..", p); } abts_suite *testfnmatch(abts_suite *suite) { suite = ADD_SUITE(suite) abts_run_test(suite, test_glob, NULL); abts_run_test(suite, test_glob_currdir, NULL); return suite; }
001-log4cxx
trunk/src/apr/test/testfnmatch.c
C
asf20
2,291
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "testutil.h" #include "apr_mmap.h" #include "apr_errno.h" #include "apr_general.h" #include "apr_lib.h" #include "apr_file_io.h" #include "apr_strings.h" /* hmmm, what is a truly portable define for the max path * length on a platform? */ #define PATH_LEN 255 #define TEST_STRING "This is the MMAP data file."APR_EOL_STR #if !APR_HAS_MMAP static void not_implemented(abts_case *tc, void *data) { ABTS_NOT_IMPL(tc, "User functions"); } #else static apr_mmap_t *themmap = NULL; static apr_file_t *thefile = NULL; static char *file1; static apr_finfo_t finfo; static int fsize; static void create_filename(abts_case *tc, void *data) { char *oldfileptr; apr_filepath_get(&file1, 0, p); #ifndef NETWARE #ifdef WIN32 ABTS_TRUE(tc, file1[1] == ':'); #else ABTS_TRUE(tc, file1[0] == '/'); #endif #endif ABTS_TRUE(tc, file1[strlen(file1) - 1] != '/'); oldfileptr = file1; file1 = apr_pstrcat(p, file1,"/data/mmap_datafile.txt" ,NULL); ABTS_TRUE(tc, oldfileptr != file1); } static void test_file_close(abts_case *tc, void *data) { apr_status_t rv; rv = apr_file_close(thefile); ABTS_INT_EQUAL(tc, rv, APR_SUCCESS); } static void test_file_open(abts_case *tc, void *data) { apr_status_t rv; rv = apr_file_open(&thefile, file1, APR_READ, APR_UREAD | APR_GREAD, p); ABTS_INT_EQUAL(tc, rv, APR_SUCCESS); ABTS_PTR_NOTNULL(tc, thefile); } static void test_get_filesize(abts_case *tc, void *data) { apr_status_t rv; rv = apr_file_info_get(&finfo, APR_FINFO_NORM, thefile); ABTS_INT_EQUAL(tc, rv, APR_SUCCESS); ABTS_ASSERT(tc, "File size mismatch", fsize == finfo.size); } static void test_mmap_create(abts_case *tc, void *data) { apr_status_t rv; rv = apr_mmap_create(&themmap, thefile, 0, (apr_size_t) finfo.size, APR_MMAP_READ, p); ABTS_PTR_NOTNULL(tc, themmap); ABTS_INT_EQUAL(tc, rv, APR_SUCCESS); } static void test_mmap_contents(abts_case *tc, void *data) { ABTS_PTR_NOTNULL(tc, themmap); ABTS_PTR_NOTNULL(tc, themmap->mm); ABTS_INT_EQUAL(tc, fsize, themmap->size); /* Must use nEquals since the string is not guaranteed to be NULL terminated */ ABTS_STR_NEQUAL(tc, themmap->mm, TEST_STRING, fsize); } static void test_mmap_delete(abts_case *tc, void *data) { apr_status_t rv; ABTS_PTR_NOTNULL(tc, themmap); rv = apr_mmap_delete(themmap); ABTS_INT_EQUAL(tc, rv, APR_SUCCESS); } static void test_mmap_offset(abts_case *tc, void *data) { apr_status_t rv; void *addr; ABTS_PTR_NOTNULL(tc, themmap); rv = apr_mmap_offset(&addr, themmap, 5); /* Must use nEquals since the string is not guaranteed to be NULL terminated */ ABTS_STR_NEQUAL(tc, addr, TEST_STRING + 5, fsize-5); } #endif abts_suite *testmmap(abts_suite *suite) { suite = ADD_SUITE(suite) #if APR_HAS_MMAP fsize = strlen(TEST_STRING); abts_run_test(suite, create_filename, NULL); abts_run_test(suite, test_file_open, NULL); abts_run_test(suite, test_get_filesize, NULL); abts_run_test(suite, test_mmap_create, NULL); abts_run_test(suite, test_mmap_contents, NULL); abts_run_test(suite, test_mmap_offset, NULL); abts_run_test(suite, test_mmap_delete, NULL); abts_run_test(suite, test_file_close, NULL); #else abts_run_test(suite, not_implemented, NULL); #endif return suite; }
001-log4cxx
trunk/src/apr/test/testmmap.c
C
asf20
4,212
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "testutil.h" #include "apr_file_io.h" #include "apr_file_info.h" #include "apr_errno.h" #include "apr_general.h" #include "apr_pools.h" #include "apr_lib.h" #if WIN32 #define ABS_ROOT "C:/" #elif defined(NETWARE) #define ABS_ROOT "SYS:/" #else #define ABS_ROOT "/" #endif static void merge_aboveroot(abts_case *tc, void *data) { apr_status_t rv; char *dstpath = NULL; char errmsg[256]; rv = apr_filepath_merge(&dstpath, ABS_ROOT"foo", ABS_ROOT"bar", APR_FILEPATH_NOTABOVEROOT, p); apr_strerror(rv, errmsg, sizeof(errmsg)); ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_EABOVEROOT(rv)); ABTS_PTR_EQUAL(tc, NULL, dstpath); ABTS_STR_EQUAL(tc, "The given path was above the root path", errmsg); } static void merge_belowroot(abts_case *tc, void *data) { apr_status_t rv; char *dstpath = NULL; rv = apr_filepath_merge(&dstpath, ABS_ROOT"foo", ABS_ROOT"foo/bar", APR_FILEPATH_NOTABOVEROOT, p); ABTS_PTR_NOTNULL(tc, dstpath); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_STR_EQUAL(tc, ABS_ROOT"foo/bar", dstpath); } static void merge_noflag(abts_case *tc, void *data) { apr_status_t rv; char *dstpath = NULL; rv = apr_filepath_merge(&dstpath, ABS_ROOT"foo", ABS_ROOT"foo/bar", 0, p); ABTS_PTR_NOTNULL(tc, dstpath); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_STR_EQUAL(tc, ABS_ROOT"foo/bar", dstpath); } static void merge_dotdot(abts_case *tc, void *data) { apr_status_t rv; char *dstpath = NULL; rv = apr_filepath_merge(&dstpath, ABS_ROOT"foo/bar", "../baz", 0, p); ABTS_PTR_NOTNULL(tc, dstpath); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_STR_EQUAL(tc, ABS_ROOT"foo/baz", dstpath); rv = apr_filepath_merge(&dstpath, "", "../test", 0, p); ABTS_INT_EQUAL(tc, 0, APR_SUCCESS); ABTS_STR_EQUAL(tc, "../test", dstpath); /* Very dangerous assumptions here about what the cwd is. However, let's assume * that the testall is invoked from within apr/test/ so the following test should * return ../test unless a previously fixed bug remains or the developer changes * the case of the test directory: */ rv = apr_filepath_merge(&dstpath, "", "../test", APR_FILEPATH_TRUENAME, p); ABTS_INT_EQUAL(tc, 0, APR_SUCCESS); ABTS_STR_EQUAL(tc, "../test", dstpath); } static void merge_dotdot_dotdot_dotdot(abts_case *tc, void *data) { apr_status_t rv; char *dstpath = NULL; rv = apr_filepath_merge(&dstpath, "", "../../..", APR_FILEPATH_TRUENAME, p); ABTS_PTR_NOTNULL(tc, dstpath); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_STR_EQUAL(tc, "../../..", dstpath); rv = apr_filepath_merge(&dstpath, "", "../../../", APR_FILEPATH_TRUENAME, p); ABTS_PTR_NOTNULL(tc, dstpath); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_STR_EQUAL(tc, "../../../", dstpath); } static void merge_secure(abts_case *tc, void *data) { apr_status_t rv; char *dstpath = NULL; rv = apr_filepath_merge(&dstpath, ABS_ROOT"foo/bar", "../bar/baz", 0, p); ABTS_PTR_NOTNULL(tc, dstpath); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_STR_EQUAL(tc, ABS_ROOT"foo/bar/baz", dstpath); } static void merge_notrel(abts_case *tc, void *data) { apr_status_t rv; char *dstpath = NULL; rv = apr_filepath_merge(&dstpath, ABS_ROOT"foo/bar", "../baz", APR_FILEPATH_NOTRELATIVE, p); ABTS_PTR_NOTNULL(tc, dstpath); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_STR_EQUAL(tc, ABS_ROOT"foo/baz", dstpath); } static void merge_notrelfail(abts_case *tc, void *data) { apr_status_t rv; char *dstpath = NULL; char errmsg[256]; rv = apr_filepath_merge(&dstpath, "foo/bar", "../baz", APR_FILEPATH_NOTRELATIVE, p); apr_strerror(rv, errmsg, sizeof(errmsg)); ABTS_PTR_EQUAL(tc, NULL, dstpath); ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_ERELATIVE(rv)); ABTS_STR_EQUAL(tc, "The given path is relative", errmsg); } static void merge_notabsfail(abts_case *tc, void *data) { apr_status_t rv; char *dstpath = NULL; char errmsg[256]; rv = apr_filepath_merge(&dstpath, ABS_ROOT"foo/bar", "../baz", APR_FILEPATH_NOTABSOLUTE, p); apr_strerror(rv, errmsg, sizeof(errmsg)); ABTS_PTR_EQUAL(tc, NULL, dstpath); ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_EABSOLUTE(rv)); ABTS_STR_EQUAL(tc, "The given path is absolute", errmsg); } static void merge_notabs(abts_case *tc, void *data) { apr_status_t rv; char *dstpath = NULL; rv = apr_filepath_merge(&dstpath, "foo/bar", "../baz", APR_FILEPATH_NOTABSOLUTE, p); ABTS_PTR_NOTNULL(tc, dstpath); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_STR_EQUAL(tc, "foo/baz", dstpath); } static void root_absolute(abts_case *tc, void *data) { apr_status_t rv; const char *root = NULL; const char *path = ABS_ROOT"foo/bar"; rv = apr_filepath_root(&root, &path, 0, p); ABTS_PTR_NOTNULL(tc, root); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_STR_EQUAL(tc, ABS_ROOT, root); } static void root_relative(abts_case *tc, void *data) { apr_status_t rv; const char *root = NULL; const char *path = "foo/bar"; char errmsg[256]; rv = apr_filepath_root(&root, &path, 0, p); apr_strerror(rv, errmsg, sizeof(errmsg)); ABTS_PTR_EQUAL(tc, NULL, root); ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_ERELATIVE(rv)); ABTS_STR_EQUAL(tc, "The given path is relative", errmsg); } static void root_from_slash(abts_case *tc, void *data) { apr_status_t rv; const char *root = NULL; const char *path = "//"; rv = apr_filepath_root(&root, &path, APR_FILEPATH_TRUENAME, p); #if defined(WIN32) || defined(OS2) ABTS_INT_EQUAL(tc, APR_EINCOMPLETE, rv); ABTS_STR_EQUAL(tc, "//", root); #else ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_STR_EQUAL(tc, "/", root); #endif ABTS_STR_EQUAL(tc, "", path); } static void root_from_cwd_and_back(abts_case *tc, void *data) { apr_status_t rv; const char *root = NULL; const char *path = "//"; char *origpath; char *testpath; ABTS_INT_EQUAL(tc, APR_SUCCESS, apr_filepath_get(&origpath, 0, p)); path = origpath; rv = apr_filepath_root(&root, &path, APR_FILEPATH_TRUENAME, p); #if defined(WIN32) || defined(OS2) ABTS_INT_EQUAL(tc, origpath[0], root[0]); ABTS_INT_EQUAL(tc, ':', root[1]); ABTS_INT_EQUAL(tc, '/', root[2]); ABTS_INT_EQUAL(tc, 0, root[3]); ABTS_STR_EQUAL(tc, origpath + 3, path); #elif defined(NETWARE) ABTS_INT_EQUAL(tc, origpath[0], root[0]); { char *pt = strchr(root, ':'); ABTS_PTR_NOTNULL(tc, pt); ABTS_INT_EQUAL(tc, ':', pt[0]); ABTS_INT_EQUAL(tc, '/', pt[1]); ABTS_INT_EQUAL(tc, 0, pt[2]); pt = strchr(origpath, ':'); ABTS_PTR_NOTNULL(tc, pt); ABTS_STR_EQUAL(tc, (pt+2), path); } #else ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_STR_EQUAL(tc, "/", root); ABTS_STR_EQUAL(tc, origpath + 1, path); #endif rv = apr_filepath_merge(&testpath, root, path, APR_FILEPATH_TRUENAME | APR_FILEPATH_NOTABOVEROOT | APR_FILEPATH_NOTRELATIVE, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_STR_EQUAL(tc, origpath, testpath); } abts_suite *testnames(abts_suite *suite) { suite = ADD_SUITE(suite) abts_run_test(suite, merge_aboveroot, NULL); abts_run_test(suite, merge_belowroot, NULL); abts_run_test(suite, merge_noflag, NULL); abts_run_test(suite, merge_dotdot, NULL); abts_run_test(suite, merge_secure, NULL); abts_run_test(suite, merge_notrel, NULL); abts_run_test(suite, merge_notrelfail, NULL); abts_run_test(suite, merge_notabs, NULL); abts_run_test(suite, merge_notabsfail, NULL); abts_run_test(suite, merge_dotdot_dotdot_dotdot, NULL); abts_run_test(suite, root_absolute, NULL); abts_run_test(suite, root_relative, NULL); abts_run_test(suite, root_from_slash, NULL); abts_run_test(suite, root_from_cwd_and_back, NULL); return suite; }
001-log4cxx
trunk/src/apr/test/testnames.c
C
asf20
9,000
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "testutil.h" #include "apr_file_io.h" #include "apr_strings.h" static void test_temp_dir(abts_case *tc, void *data) { const char *tempdir = NULL; apr_status_t rv; rv = apr_temp_dir_get(&tempdir, p); APR_ASSERT_SUCCESS(tc, "Error finding Temporary Directory", rv); ABTS_PTR_NOTNULL(tc, tempdir); } static void test_mktemp(abts_case *tc, void *data) { apr_file_t *f = NULL; const char *tempdir = NULL; char *filetemplate; apr_status_t rv; rv = apr_temp_dir_get(&tempdir, p); APR_ASSERT_SUCCESS(tc, "Error finding Temporary Directory", rv); filetemplate = apr_pstrcat(p, tempdir, "/tempfileXXXXXX", NULL); rv = apr_file_mktemp(&f, filetemplate, 0, p); APR_ASSERT_SUCCESS(tc, "Error opening Temporary file", rv); } abts_suite *testtemp(abts_suite *suite) { suite = ADD_SUITE(suite) abts_run_test(suite, test_temp_dir, NULL); abts_run_test(suite, test_mktemp, NULL); return suite; }
001-log4cxx
trunk/src/apr/test/testtemp.c
C
asf20
1,772
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <assert.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> #include "apr.h" #include "apr_general.h" #include "apr_proc_mutex.h" #include "apr_global_mutex.h" #include "apr_thread_proc.h" #if !APR_HAS_THREADS int main(void) { printf("This test requires APR thread support.\n"); return 0; } #else /* APR_HAS_THREADS */ static apr_thread_mutex_t *thread_mutex; static apr_proc_mutex_t *proc_mutex; static apr_global_mutex_t *global_mutex; static apr_pool_t *p; static volatile int counter; typedef enum {TEST_GLOBAL, TEST_PROC} test_mode_e; static void lock_init(apr_lockmech_e mech, test_mode_e test_mode) { if (test_mode == TEST_PROC) { assert(apr_proc_mutex_create(&proc_mutex, NULL, mech, p) == APR_SUCCESS); } else { assert(apr_global_mutex_create(&global_mutex, NULL, mech, p) == APR_SUCCESS); } } static void lock_destroy(test_mode_e test_mode) { if (test_mode == TEST_PROC) { assert(apr_proc_mutex_destroy(proc_mutex) == APR_SUCCESS); } else { assert(apr_global_mutex_destroy(global_mutex) == APR_SUCCESS); } } static void lock_grab(test_mode_e test_mode) { if (test_mode == TEST_PROC) { assert(apr_proc_mutex_lock(proc_mutex) == APR_SUCCESS); } else { assert(apr_global_mutex_lock(global_mutex) == APR_SUCCESS); } } static void lock_release(test_mode_e test_mode) { if (test_mode == TEST_PROC) { assert(apr_proc_mutex_unlock(proc_mutex) == APR_SUCCESS); } else { assert(apr_global_mutex_unlock(global_mutex) == APR_SUCCESS); } } static void * APR_THREAD_FUNC eachThread(apr_thread_t *id, void *p) { test_mode_e test_mode = (test_mode_e)p; lock_grab(test_mode); ++counter; assert(apr_thread_mutex_lock(thread_mutex) == APR_SUCCESS); assert(apr_thread_mutex_unlock(thread_mutex) == APR_SUCCESS); lock_release(test_mode); return NULL; } static void test_mech_mode(apr_lockmech_e mech, const char *mech_name, test_mode_e test_mode) { apr_thread_t *threads[20]; int numThreads = 5; int i; apr_status_t rv; printf("Trying %s mutexes with mechanism `%s'...\n", test_mode == TEST_GLOBAL ? "global" : "proc", mech_name); assert(numThreads <= sizeof(threads) / sizeof(threads[0])); assert(apr_pool_create(&p, NULL) == APR_SUCCESS); assert(apr_thread_mutex_create(&thread_mutex, 0, p) == APR_SUCCESS); assert(apr_thread_mutex_lock(thread_mutex) == APR_SUCCESS); lock_init(mech, test_mode); counter = 0; i = 0; while (i < numThreads) { rv = apr_thread_create(&threads[i], NULL, eachThread, (void *)test_mode, p); if (rv != APR_SUCCESS) { fprintf(stderr, "apr_thread_create->%d\n", rv); exit(1); } ++i; } apr_sleep(apr_time_from_sec(5)); if (test_mode == TEST_PROC) { printf(" Mutex mechanism `%s' is %sglobal in scope on this platform.\n", mech_name, counter == 1 ? "" : "not "); } else { if (counter != 1) { fprintf(stderr, "\n!!!apr_global_mutex operations are broken on this " "platform for mutex mechanism `%s'!\n" "They don't block out threads within the same process.\n", mech_name); fprintf(stderr, "counter value: %d\n", counter); exit(1); } else { printf(" no problems encountered...\n"); } } assert(apr_thread_mutex_unlock(thread_mutex) == APR_SUCCESS); i = 0; while (i < numThreads) { apr_status_t ignored; rv = apr_thread_join(&ignored, threads[i]); assert(rv == APR_SUCCESS); ++i; } lock_destroy(test_mode); apr_thread_mutex_destroy(thread_mutex); apr_pool_destroy(p); } static void test_mech(apr_lockmech_e mech, const char *mech_name) { test_mech_mode(mech, mech_name, TEST_PROC); test_mech_mode(mech, mech_name, TEST_GLOBAL); } int main(void) { struct { apr_lockmech_e mech; const char *mech_name; } lockmechs[] = { {APR_LOCK_DEFAULT, "default"} #if APR_HAS_FLOCK_SERIALIZE ,{APR_LOCK_FLOCK, "flock"} #endif #if APR_HAS_SYSVSEM_SERIALIZE ,{APR_LOCK_SYSVSEM, "sysvsem"} #endif #if APR_HAS_POSIXSEM_SERIALIZE ,{APR_LOCK_POSIXSEM, "posix"} #endif #if APR_HAS_FCNTL_SERIALIZE ,{APR_LOCK_FCNTL, "fcntl"} #endif #if APR_HAS_PROC_PTHREAD_SERIALIZE ,{APR_LOCK_PROC_PTHREAD, "proc_pthread"} #endif }; int i; assert(apr_initialize() == APR_SUCCESS); for (i = 0; i < sizeof(lockmechs) / sizeof(lockmechs[0]); i++) { test_mech(lockmechs[i].mech, lockmechs[i].mech_name); } apr_terminate(); return 0; } #endif /* APR_HAS_THREADS */
001-log4cxx
trunk/src/apr/test/testmutexscope.c
C
asf20
5,911
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "testutil.h" #include "apr_strings.h" #include "apr_thread_proc.h" #include "apr_errno.h" #include "apr_general.h" #include "apr_atomic.h" #include "apr_time.h" /* Use pthread_setconcurrency where it is available and not a nullop, * i.e. platforms using M:N or M:1 thread models: */ #if APR_HAS_THREADS && \ ((defined(SOLARIS2) && SOLARIS2 > 26) || defined(_AIX)) /* also HP-UX, IRIX? ... */ #define HAVE_PTHREAD_SETCONCURRENCY #endif #ifdef HAVE_PTHREAD_SETCONCURRENCY #include <pthread.h> #endif static void test_init(abts_case *tc, void *data) { APR_ASSERT_SUCCESS(tc, "Could not initliaze atomics", apr_atomic_init(p)); } static void test_set32(abts_case *tc, void *data) { apr_uint32_t y32; apr_atomic_set32(&y32, 2); ABTS_INT_EQUAL(tc, 2, y32); } static void test_read32(abts_case *tc, void *data) { apr_uint32_t y32; apr_atomic_set32(&y32, 2); ABTS_INT_EQUAL(tc, 2, apr_atomic_read32(&y32)); } static void test_dec32(abts_case *tc, void *data) { apr_uint32_t y32; int rv; apr_atomic_set32(&y32, 2); rv = apr_atomic_dec32(&y32); ABTS_INT_EQUAL(tc, 1, y32); ABTS_ASSERT(tc, "atomic_dec returned zero when it shouldn't", rv != 0); rv = apr_atomic_dec32(&y32); ABTS_INT_EQUAL(tc, 0, y32); ABTS_ASSERT(tc, "atomic_dec didn't returned zero when it should", rv == 0); } static void test_xchg32(abts_case *tc, void *data) { apr_uint32_t oldval; apr_uint32_t y32; apr_atomic_set32(&y32, 100); oldval = apr_atomic_xchg32(&y32, 50); ABTS_INT_EQUAL(tc, 100, oldval); ABTS_INT_EQUAL(tc, 50, y32); } static void test_cas_equal(abts_case *tc, void *data) { apr_uint32_t casval = 0; apr_uint32_t oldval; oldval = apr_atomic_cas32(&casval, 12, 0); ABTS_INT_EQUAL(tc, 0, oldval); ABTS_INT_EQUAL(tc, 12, casval); } static void test_cas_equal_nonnull(abts_case *tc, void *data) { apr_uint32_t casval = 12; apr_uint32_t oldval; oldval = apr_atomic_cas32(&casval, 23, 12); ABTS_INT_EQUAL(tc, 12, oldval); ABTS_INT_EQUAL(tc, 23, casval); } static void test_cas_notequal(abts_case *tc, void *data) { apr_uint32_t casval = 12; apr_uint32_t oldval; oldval = apr_atomic_cas32(&casval, 23, 2); ABTS_INT_EQUAL(tc, 12, oldval); ABTS_INT_EQUAL(tc, 12, casval); } static void test_add32(abts_case *tc, void *data) { apr_uint32_t oldval; apr_uint32_t y32; apr_atomic_set32(&y32, 23); oldval = apr_atomic_add32(&y32, 4); ABTS_INT_EQUAL(tc, 23, oldval); ABTS_INT_EQUAL(tc, 27, y32); } static void test_inc32(abts_case *tc, void *data) { apr_uint32_t oldval; apr_uint32_t y32; apr_atomic_set32(&y32, 23); oldval = apr_atomic_inc32(&y32); ABTS_INT_EQUAL(tc, 23, oldval); ABTS_INT_EQUAL(tc, 24, y32); } static void test_set_add_inc_sub(abts_case *tc, void *data) { apr_uint32_t y32; apr_atomic_set32(&y32, 0); apr_atomic_add32(&y32, 20); apr_atomic_inc32(&y32); apr_atomic_sub32(&y32, 10); ABTS_INT_EQUAL(tc, 11, y32); } static void test_wrap_zero(abts_case *tc, void *data) { apr_uint32_t y32; apr_uint32_t rv; apr_uint32_t minus1 = -1; char *str; apr_atomic_set32(&y32, 0); rv = apr_atomic_dec32(&y32); ABTS_ASSERT(tc, "apr_atomic_dec32 on zero returned zero.", rv != 0); str = apr_psprintf(p, "zero wrap failed: 0 - 1 = %d", y32); ABTS_ASSERT(tc, str, y32 == minus1); } static void test_inc_neg1(abts_case *tc, void *data) { apr_uint32_t y32 = -1; apr_uint32_t minus1 = -1; apr_uint32_t rv; char *str; rv = apr_atomic_inc32(&y32); ABTS_ASSERT(tc, "apr_atomic_dec32 on zero returned zero.", rv == minus1); str = apr_psprintf(p, "zero wrap failed: -1 + 1 = %d", y32); ABTS_ASSERT(tc, str, y32 == 0); } #if APR_HAS_THREADS void * APR_THREAD_FUNC thread_func_mutex(apr_thread_t *thd, void *data); void * APR_THREAD_FUNC thread_func_atomic(apr_thread_t *thd, void *data); void * APR_THREAD_FUNC thread_func_none(apr_thread_t *thd, void *data); apr_thread_mutex_t *thread_lock; volatile apr_uint32_t x = 0; /* mutex locks */ volatile apr_uint32_t y = 0; /* atomic operations */ volatile apr_uint32_t z = 0; /* no locks */ apr_status_t exit_ret_val = 123; /* just some made up number to check on later */ #define NUM_THREADS 40 #define NUM_ITERATIONS 20000 void * APR_THREAD_FUNC thread_func_mutex(apr_thread_t *thd, void *data) { int i; for (i = 0; i < NUM_ITERATIONS; i++) { apr_thread_mutex_lock(thread_lock); x++; apr_thread_mutex_unlock(thread_lock); } apr_thread_exit(thd, exit_ret_val); return NULL; } void * APR_THREAD_FUNC thread_func_atomic(apr_thread_t *thd, void *data) { int i; for (i = 0; i < NUM_ITERATIONS ; i++) { apr_atomic_inc32(&y); apr_atomic_add32(&y, 2); apr_atomic_dec32(&y); apr_atomic_dec32(&y); } apr_thread_exit(thd, exit_ret_val); return NULL; } void * APR_THREAD_FUNC thread_func_none(apr_thread_t *thd, void *data) { int i; for (i = 0; i < NUM_ITERATIONS ; i++) { z++; } apr_thread_exit(thd, exit_ret_val); return NULL; } static void test_atomics_threaded(abts_case *tc, void *data) { apr_thread_t *t1[NUM_THREADS]; apr_thread_t *t2[NUM_THREADS]; apr_thread_t *t3[NUM_THREADS]; apr_status_t s1[NUM_THREADS]; apr_status_t s2[NUM_THREADS]; apr_status_t s3[NUM_THREADS]; apr_status_t rv; int i; #ifdef HAVE_PTHREAD_SETCONCURRENCY pthread_setconcurrency(8); #endif rv = apr_thread_mutex_create(&thread_lock, APR_THREAD_MUTEX_DEFAULT, p); APR_ASSERT_SUCCESS(tc, "Could not create lock", rv); for (i = 0; i < NUM_THREADS; i++) { apr_status_t r1, r2, r3; r1 = apr_thread_create(&t1[i], NULL, thread_func_mutex, NULL, p); r2 = apr_thread_create(&t2[i], NULL, thread_func_atomic, NULL, p); r3 = apr_thread_create(&t3[i], NULL, thread_func_none, NULL, p); ABTS_ASSERT(tc, "Failed creating threads", r1 == APR_SUCCESS && r2 == APR_SUCCESS && r3 == APR_SUCCESS); } for (i = 0; i < NUM_THREADS; i++) { apr_thread_join(&s1[i], t1[i]); apr_thread_join(&s2[i], t2[i]); apr_thread_join(&s3[i], t3[i]); ABTS_ASSERT(tc, "Invalid return value from thread_join", s1[i] == exit_ret_val && s2[i] == exit_ret_val && s3[i] == exit_ret_val); } ABTS_INT_EQUAL(tc, x, NUM_THREADS * NUM_ITERATIONS); ABTS_INT_EQUAL(tc, apr_atomic_read32(&y), NUM_THREADS * NUM_ITERATIONS); /* Comment out this test, because I have no clue what this test is * actually telling us. We are checking something that may or may not * be true, and it isn't really testing APR at all. ABTS_ASSERT(tc, "We expect this to fail, because we tried to update " "an integer in a non-thread-safe manner.", z != NUM_THREADS * NUM_ITERATIONS); */ } #endif /* !APR_HAS_THREADS */ abts_suite *testatomic(abts_suite *suite) { suite = ADD_SUITE(suite) abts_run_test(suite, test_init, NULL); abts_run_test(suite, test_set32, NULL); abts_run_test(suite, test_read32, NULL); abts_run_test(suite, test_dec32, NULL); abts_run_test(suite, test_xchg32, NULL); abts_run_test(suite, test_cas_equal, NULL); abts_run_test(suite, test_cas_equal_nonnull, NULL); abts_run_test(suite, test_cas_notequal, NULL); abts_run_test(suite, test_add32, NULL); abts_run_test(suite, test_inc32, NULL); abts_run_test(suite, test_set_add_inc_sub, NULL); abts_run_test(suite, test_wrap_zero, NULL); abts_run_test(suite, test_inc_neg1, NULL); #if APR_HAS_THREADS abts_run_test(suite, test_atomics_threaded, NULL); #endif return suite; }
001-log4cxx
trunk/src/apr/test/testatomic.c
C
asf20
8,665
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef TESTSOCK_H #define TESTSOCK_H #define DATASTR "This is a test" #define STRLEN 8092 /* This is a hack. We can't return APR_TIMEOUT from sockchild, because * Unix OSes only return the least significant 8 bits of the return code, * which means that instead of receiving 70007, testsock gets 119. But, * we also don't want to return -1, because we use that value for general * errors from sockchild. So, we define 1 to mean that the read/write * operation timed out. This means that we can't write a test that tries * to send a single character between ends of the socket. */ #define SOCKET_TIMEOUT 1 #endif
001-log4cxx
trunk/src/apr/test/testsock.h
C
asf20
1,427
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "apr_file_io.h" #include "apr_file_info.h" #include "apr_network_io.h" #include "apr_errno.h" #include "apr_general.h" #include "apr_poll.h" #include "apr_lib.h" #include "testutil.h" #define DIRNAME "data" #define FILENAME DIRNAME "/file_datafile.txt" #define TESTSTR "This is the file data file." #define TESTREAD_BLKSIZE 1024 #define APR_BUFFERSIZE 4096 /* This should match APR's buffer size. */ static void test_open_noreadwrite(abts_case *tc, void *data) { apr_status_t rv; apr_file_t *thefile = NULL; rv = apr_file_open(&thefile, FILENAME, APR_CREATE | APR_EXCL, APR_UREAD | APR_UWRITE | APR_GREAD, p); ABTS_TRUE(tc, rv != APR_SUCCESS); ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_EACCES(rv)); ABTS_PTR_EQUAL(tc, NULL, thefile); } static void test_open_excl(abts_case *tc, void *data) { apr_status_t rv; apr_file_t *thefile = NULL; rv = apr_file_open(&thefile, FILENAME, APR_CREATE | APR_EXCL | APR_WRITE, APR_UREAD | APR_UWRITE | APR_GREAD, p); ABTS_TRUE(tc, rv != APR_SUCCESS); ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_EEXIST(rv)); ABTS_PTR_EQUAL(tc, NULL, thefile); } static void test_open_read(abts_case *tc, void *data) { apr_status_t rv; apr_file_t *filetest = NULL; rv = apr_file_open(&filetest, FILENAME, APR_READ, APR_UREAD | APR_UWRITE | APR_GREAD, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_PTR_NOTNULL(tc, filetest); apr_file_close(filetest); } static void test_read(abts_case *tc, void *data) { apr_status_t rv; apr_size_t nbytes = 256; char *str = apr_pcalloc(p, nbytes + 1); apr_file_t *filetest = NULL; rv = apr_file_open(&filetest, FILENAME, APR_READ, APR_UREAD | APR_UWRITE | APR_GREAD, p); APR_ASSERT_SUCCESS(tc, "Opening test file " FILENAME, rv); rv = apr_file_read(filetest, str, &nbytes); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, strlen(TESTSTR), nbytes); ABTS_STR_EQUAL(tc, TESTSTR, str); apr_file_close(filetest); } static void test_readzero(abts_case *tc, void *data) { apr_status_t rv; apr_size_t nbytes = 0; char *str = NULL; apr_file_t *filetest; rv = apr_file_open(&filetest, FILENAME, APR_READ, APR_OS_DEFAULT, p); APR_ASSERT_SUCCESS(tc, "Opening test file " FILENAME, rv); rv = apr_file_read(filetest, str, &nbytes); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, 0, nbytes); apr_file_close(filetest); } static void test_filename(abts_case *tc, void *data) { const char *str; apr_status_t rv; apr_file_t *filetest = NULL; rv = apr_file_open(&filetest, FILENAME, APR_READ, APR_UREAD | APR_UWRITE | APR_GREAD, p); APR_ASSERT_SUCCESS(tc, "Opening test file " FILENAME, rv); rv = apr_file_name_get(&str, filetest); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_STR_EQUAL(tc, FILENAME, str); apr_file_close(filetest); } static void test_fileclose(abts_case *tc, void *data) { char str; apr_status_t rv; apr_size_t one = 1; apr_file_t *filetest = NULL; rv = apr_file_open(&filetest, FILENAME, APR_READ, APR_UREAD | APR_UWRITE | APR_GREAD, p); APR_ASSERT_SUCCESS(tc, "Opening test file " FILENAME, rv); rv = apr_file_close(filetest); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); /* We just closed the file, so this should fail */ rv = apr_file_read(filetest, &str, &one); ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_EBADF(rv)); } static void test_file_remove(abts_case *tc, void *data) { apr_status_t rv; apr_file_t *filetest = NULL; rv = apr_file_remove(FILENAME, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_file_open(&filetest, FILENAME, APR_READ, APR_UREAD | APR_UWRITE | APR_GREAD, p); ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_ENOENT(rv)); } static void test_open_write(abts_case *tc, void *data) { apr_status_t rv; apr_file_t *filetest = NULL; filetest = NULL; rv = apr_file_open(&filetest, FILENAME, APR_WRITE, APR_UREAD | APR_UWRITE | APR_GREAD, p); ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_ENOENT(rv)); ABTS_PTR_EQUAL(tc, NULL, filetest); } static void test_open_writecreate(abts_case *tc, void *data) { apr_status_t rv; apr_file_t *filetest = NULL; filetest = NULL; rv = apr_file_open(&filetest, FILENAME, APR_WRITE | APR_CREATE, APR_UREAD | APR_UWRITE | APR_GREAD, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); apr_file_close(filetest); } static void test_write(abts_case *tc, void *data) { apr_status_t rv; apr_size_t bytes = strlen(TESTSTR); apr_file_t *filetest = NULL; rv = apr_file_open(&filetest, FILENAME, APR_WRITE | APR_CREATE, APR_UREAD | APR_UWRITE | APR_GREAD, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_file_write(filetest, TESTSTR, &bytes); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); apr_file_close(filetest); } static void test_open_readwrite(abts_case *tc, void *data) { apr_status_t rv; apr_file_t *filetest = NULL; filetest = NULL; rv = apr_file_open(&filetest, FILENAME, APR_READ | APR_WRITE, APR_UREAD | APR_UWRITE | APR_GREAD, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_PTR_NOTNULL(tc, filetest); apr_file_close(filetest); } static void test_seek(abts_case *tc, void *data) { apr_status_t rv; apr_off_t offset = 5; apr_size_t nbytes = 256; char *str = apr_pcalloc(p, nbytes + 1); apr_file_t *filetest = NULL; rv = apr_file_open(&filetest, FILENAME, APR_READ, APR_UREAD | APR_UWRITE | APR_GREAD, p); APR_ASSERT_SUCCESS(tc, "Open test file " FILENAME, rv); rv = apr_file_read(filetest, str, &nbytes); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, strlen(TESTSTR), nbytes); ABTS_STR_EQUAL(tc, TESTSTR, str); memset(str, 0, nbytes + 1); rv = apr_file_seek(filetest, SEEK_SET, &offset); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_file_read(filetest, str, &nbytes); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, strlen(TESTSTR) - 5, nbytes); ABTS_STR_EQUAL(tc, TESTSTR + 5, str); apr_file_close(filetest); /* Test for regression of sign error bug with SEEK_END and buffered files. */ rv = apr_file_open(&filetest, FILENAME, APR_READ | APR_BUFFERED, APR_UREAD | APR_UWRITE | APR_GREAD, p); APR_ASSERT_SUCCESS(tc, "Open test file " FILENAME, rv); offset = -5; rv = apr_file_seek(filetest, SEEK_END, &offset); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, strlen(TESTSTR) - 5, nbytes); memset(str, 0, nbytes + 1); nbytes = 256; rv = apr_file_read(filetest, str, &nbytes); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, 5, nbytes); ABTS_STR_EQUAL(tc, TESTSTR + strlen(TESTSTR) - 5, str); apr_file_close(filetest); } static void test_userdata_set(abts_case *tc, void *data) { apr_status_t rv; apr_file_t *filetest = NULL; rv = apr_file_open(&filetest, FILENAME, APR_WRITE, APR_UREAD | APR_UWRITE | APR_GREAD, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_file_data_set(filetest, "This is a test", "test", apr_pool_cleanup_null); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); apr_file_close(filetest); } static void test_userdata_get(abts_case *tc, void *data) { apr_status_t rv; void *udata; char *teststr; apr_file_t *filetest = NULL; rv = apr_file_open(&filetest, FILENAME, APR_WRITE, APR_UREAD | APR_UWRITE | APR_GREAD, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_file_data_set(filetest, "This is a test", "test", apr_pool_cleanup_null); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_file_data_get(&udata, "test", filetest); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); teststr = udata; ABTS_STR_EQUAL(tc, "This is a test", teststr); apr_file_close(filetest); } static void test_userdata_getnokey(abts_case *tc, void *data) { apr_status_t rv; void *teststr; apr_file_t *filetest = NULL; rv = apr_file_open(&filetest, FILENAME, APR_WRITE, APR_UREAD | APR_UWRITE | APR_GREAD, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_file_data_get(&teststr, "nokey", filetest); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_PTR_EQUAL(tc, NULL, teststr); apr_file_close(filetest); } static void test_getc(abts_case *tc, void *data) { apr_file_t *f = NULL; apr_status_t rv; char ch; rv = apr_file_open(&f, FILENAME, APR_READ, 0, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); apr_file_getc(&ch, f); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, (int)TESTSTR[0], (int)ch); apr_file_close(f); } static void test_ungetc(abts_case *tc, void *data) { apr_file_t *f = NULL; apr_status_t rv; char ch; rv = apr_file_open(&f, FILENAME, APR_READ, 0, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); apr_file_getc(&ch, f); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, (int)TESTSTR[0], (int)ch); apr_file_ungetc('X', f); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); apr_file_getc(&ch, f); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, 'X', (int)ch); apr_file_close(f); } static void test_gets(abts_case *tc, void *data) { apr_file_t *f = NULL; apr_status_t rv; char *str = apr_palloc(p, 256); rv = apr_file_open(&f, FILENAME, APR_READ, 0, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_file_gets(str, 256, f); /* Only one line in the test file, so APR will encounter EOF on the first * call to gets, but we should get APR_SUCCESS on this call and * APR_EOF on the next. */ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_STR_EQUAL(tc, TESTSTR, str); rv = apr_file_gets(str, 256, f); ABTS_INT_EQUAL(tc, APR_EOF, rv); ABTS_STR_EQUAL(tc, "", str); apr_file_close(f); } static void test_bigread(abts_case *tc, void *data) { apr_file_t *f = NULL; apr_status_t rv; char buf[APR_BUFFERSIZE * 2]; apr_size_t nbytes; /* Create a test file with known content. */ rv = apr_file_open(&f, "data/created_file", APR_CREATE | APR_WRITE | APR_TRUNCATE, APR_UREAD | APR_UWRITE, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); nbytes = APR_BUFFERSIZE; memset(buf, 0xFE, nbytes); rv = apr_file_write(f, buf, &nbytes); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, APR_BUFFERSIZE, nbytes); rv = apr_file_close(f); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); f = NULL; rv = apr_file_open(&f, "data/created_file", APR_READ, 0, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); nbytes = sizeof buf; rv = apr_file_read(f, buf, &nbytes); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, APR_BUFFERSIZE, nbytes); rv = apr_file_close(f); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_file_remove("data/created_file", p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); } /* This is a horrible name for this function. We are testing APR, not how * Apache uses APR. And, this function tests _way_ too much stuff. */ static void test_mod_neg(abts_case *tc, void *data) { apr_status_t rv; apr_file_t *f; const char *s; int i; apr_size_t nbytes; char buf[8192]; apr_off_t cur; const char *fname = "data/modneg.dat"; rv = apr_file_open(&f, fname, APR_CREATE | APR_WRITE, APR_UREAD | APR_UWRITE, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); s = "body56789\n"; nbytes = strlen(s); rv = apr_file_write(f, s, &nbytes); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, strlen(s), nbytes); for (i = 0; i < 7980; i++) { s = "0"; nbytes = strlen(s); rv = apr_file_write(f, s, &nbytes); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, strlen(s), nbytes); } s = "end456789\n"; nbytes = strlen(s); rv = apr_file_write(f, s, &nbytes); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, strlen(s), nbytes); for (i = 0; i < 10000; i++) { s = "1"; nbytes = strlen(s); rv = apr_file_write(f, s, &nbytes); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, strlen(s), nbytes); } rv = apr_file_close(f); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_file_open(&f, fname, APR_READ, 0, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_file_gets(buf, 11, f); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_STR_EQUAL(tc, "body56789\n", buf); cur = 0; rv = apr_file_seek(f, APR_CUR, &cur); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_ASSERT(tc, "File Pointer Mismatch, expected 10", cur == 10); nbytes = sizeof(buf); rv = apr_file_read(f, buf, &nbytes); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, nbytes, sizeof(buf)); cur = -((apr_off_t)nbytes - 7980); rv = apr_file_seek(f, APR_CUR, &cur); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_ASSERT(tc, "File Pointer Mismatch, expected 7990", cur == 7990); rv = apr_file_gets(buf, 11, f); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_STR_EQUAL(tc, "end456789\n", buf); rv = apr_file_close(f); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_file_remove(fname, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); } /* Test that the contents of file FNAME are equal to data EXPECT of * length EXPECTLEN. */ static void file_contents_equal(abts_case *tc, const char *fname, const void *expect, apr_size_t expectlen) { void *actual = apr_palloc(p, expectlen); apr_file_t *f; APR_ASSERT_SUCCESS(tc, "open file", apr_file_open(&f, fname, APR_READ|APR_BUFFERED, 0, p)); APR_ASSERT_SUCCESS(tc, "read from file", apr_file_read_full(f, actual, expectlen, NULL)); ABTS_ASSERT(tc, "matched expected file contents", memcmp(expect, actual, expectlen) == 0); APR_ASSERT_SUCCESS(tc, "close file", apr_file_close(f)); } #define LINE1 "this is a line of text\n" #define LINE2 "this is a second line of text\n" static void test_puts(abts_case *tc, void *data) { apr_file_t *f; const char *fname = "data/testputs.txt"; APR_ASSERT_SUCCESS(tc, "open file for writing", apr_file_open(&f, fname, APR_WRITE|APR_CREATE|APR_TRUNCATE, APR_OS_DEFAULT, p)); APR_ASSERT_SUCCESS(tc, "write line to file", apr_file_puts(LINE1, f)); APR_ASSERT_SUCCESS(tc, "write second line to file", apr_file_puts(LINE2, f)); APR_ASSERT_SUCCESS(tc, "close for writing", apr_file_close(f)); file_contents_equal(tc, fname, LINE1 LINE2, strlen(LINE1 LINE2)); } static void test_writev(abts_case *tc, void *data) { apr_file_t *f; apr_size_t nbytes; struct iovec vec[5]; const char *fname = "data/testwritev.txt"; APR_ASSERT_SUCCESS(tc, "open file for writing", apr_file_open(&f, fname, APR_WRITE|APR_CREATE|APR_TRUNCATE, APR_OS_DEFAULT, p)); vec[0].iov_base = LINE1; vec[0].iov_len = strlen(LINE1); APR_ASSERT_SUCCESS(tc, "writev of size 1 to file", apr_file_writev(f, vec, 1, &nbytes)); file_contents_equal(tc, fname, LINE1, strlen(LINE1)); vec[0].iov_base = LINE1; vec[0].iov_len = strlen(LINE1); vec[1].iov_base = LINE2; vec[1].iov_len = strlen(LINE2); vec[2].iov_base = LINE1; vec[2].iov_len = strlen(LINE1); vec[3].iov_base = LINE1; vec[3].iov_len = strlen(LINE1); vec[4].iov_base = LINE2; vec[4].iov_len = strlen(LINE2); APR_ASSERT_SUCCESS(tc, "writev of size 5 to file", apr_file_writev(f, vec, 5, &nbytes)); APR_ASSERT_SUCCESS(tc, "close for writing", apr_file_close(f)); file_contents_equal(tc, fname, LINE1 LINE1 LINE2 LINE1 LINE1 LINE2, strlen(LINE1)*4 + strlen(LINE2)*2); } static void test_writev_full(abts_case *tc, void *data) { apr_file_t *f; apr_size_t nbytes; struct iovec vec[5]; const char *fname = "data/testwritev_full.txt"; APR_ASSERT_SUCCESS(tc, "open file for writing", apr_file_open(&f, fname, APR_WRITE|APR_CREATE|APR_TRUNCATE, APR_OS_DEFAULT, p)); vec[0].iov_base = LINE1; vec[0].iov_len = strlen(LINE1); vec[1].iov_base = LINE2; vec[1].iov_len = strlen(LINE2); vec[2].iov_base = LINE1; vec[2].iov_len = strlen(LINE1); vec[3].iov_base = LINE1; vec[3].iov_len = strlen(LINE1); vec[4].iov_base = LINE2; vec[4].iov_len = strlen(LINE2); APR_ASSERT_SUCCESS(tc, "writev_full of size 5 to file", apr_file_writev_full(f, vec, 5, &nbytes)); ABTS_INT_EQUAL(tc, strlen(LINE1)*3 + strlen(LINE2)*2, nbytes); APR_ASSERT_SUCCESS(tc, "close for writing", apr_file_close(f)); file_contents_equal(tc, fname, LINE1 LINE2 LINE1 LINE1 LINE2, strlen(LINE1)*3 + strlen(LINE2)*2); } static void test_truncate(abts_case *tc, void *data) { apr_status_t rv; apr_file_t *f; const char *fname = "data/testtruncate.dat"; const char *s; apr_size_t nbytes; apr_finfo_t finfo; apr_file_remove(fname, p); rv = apr_file_open(&f, fname, APR_CREATE | APR_WRITE, APR_UREAD | APR_UWRITE, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); s = "some data"; nbytes = strlen(s); rv = apr_file_write(f, s, &nbytes); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, strlen(s), nbytes); rv = apr_file_close(f); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_file_open(&f, fname, APR_TRUNCATE | APR_WRITE, APR_UREAD | APR_UWRITE, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_file_close(f); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_stat(&finfo, fname, APR_FINFO_SIZE, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_ASSERT(tc, "File size mismatch, expected 0 (empty)", finfo.size == 0); rv = apr_file_remove(fname, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); } static void test_bigfprintf(abts_case *tc, void *data) { apr_file_t *f; const char *fname = "data/testbigfprintf.dat"; char *to_write; int i; apr_file_remove(fname, p); APR_ASSERT_SUCCESS(tc, "open test file", apr_file_open(&f, fname, APR_CREATE|APR_WRITE, APR_UREAD|APR_UWRITE, p)); to_write = malloc(HUGE_STRING_LEN + 3); for (i = 0; i < HUGE_STRING_LEN + 1; ++i) to_write[i] = 'A' + i%26; strcpy(to_write + HUGE_STRING_LEN, "42"); i = apr_file_printf(f, "%s", to_write); ABTS_INT_EQUAL(tc, HUGE_STRING_LEN + 2, i); apr_file_close(f); file_contents_equal(tc, fname, to_write, HUGE_STRING_LEN + 2); free(to_write); } static void test_fail_write_flush(abts_case *tc, void *data) { apr_file_t *f; const char *fname = "data/testflush.dat"; apr_status_t rv; char buf[APR_BUFFERSIZE]; int n; apr_file_remove(fname, p); APR_ASSERT_SUCCESS(tc, "open test file", apr_file_open(&f, fname, APR_CREATE|APR_READ|APR_BUFFERED, APR_UREAD|APR_UWRITE, p)); memset(buf, 'A', sizeof buf); /* Try three writes. One of these should fail when it exceeds the * internal buffer and actually tries to write to the file, which * was opened read-only and hence should be unwritable. */ for (n = 0, rv = APR_SUCCESS; n < 4 && rv == APR_SUCCESS; n++) { apr_size_t bytes = sizeof buf; rv = apr_file_write(f, buf, &bytes); } ABTS_ASSERT(tc, "failed to write to read-only buffered fd", rv != APR_SUCCESS); apr_file_close(f); } static void test_fail_read_flush(abts_case *tc, void *data) { apr_file_t *f; const char *fname = "data/testflush.dat"; apr_status_t rv; char buf[2]; apr_file_remove(fname, p); APR_ASSERT_SUCCESS(tc, "open test file", apr_file_open(&f, fname, APR_CREATE|APR_READ|APR_BUFFERED, APR_UREAD|APR_UWRITE, p)); /* this write should be buffered. */ APR_ASSERT_SUCCESS(tc, "buffered write should succeed", apr_file_puts("hello", f)); /* Now, trying a read should fail since the write must be flushed, * and should fail with something other than EOF since the file is * opened read-only. */ rv = apr_file_read_full(f, buf, 2, NULL); ABTS_ASSERT(tc, "read should flush buffered write and fail", rv != APR_SUCCESS && rv != APR_EOF); /* Likewise for gets */ rv = apr_file_gets(buf, 2, f); ABTS_ASSERT(tc, "gets should flush buffered write and fail", rv != APR_SUCCESS && rv != APR_EOF); /* Likewise for seek. */ { apr_off_t offset = 0; rv = apr_file_seek(f, APR_SET, &offset); } ABTS_ASSERT(tc, "seek should flush buffered write and fail", rv != APR_SUCCESS && rv != APR_EOF); apr_file_close(f); } static void test_xthread(abts_case *tc, void *data) { apr_file_t *f; const char *fname = "data/testxthread.dat"; apr_status_t rv; apr_int32_t flags = APR_CREATE|APR_READ|APR_WRITE|APR_APPEND|APR_XTHREAD; char buf[128] = { 0 }; /* Test for bug 38438, opening file with append + xthread and seeking to the end of the file resulted in writes going to the beginning not the end. */ apr_file_remove(fname, p); APR_ASSERT_SUCCESS(tc, "open test file", apr_file_open(&f, fname, flags, APR_UREAD|APR_UWRITE, p)); APR_ASSERT_SUCCESS(tc, "write should succeed", apr_file_puts("hello", f)); apr_file_close(f); APR_ASSERT_SUCCESS(tc, "open test file", apr_file_open(&f, fname, flags, APR_UREAD|APR_UWRITE, p)); /* Seek to the end. */ { apr_off_t offset = 0; rv = apr_file_seek(f, APR_END, &offset); } APR_ASSERT_SUCCESS(tc, "more writes should succeed", apr_file_puts("world", f)); /* Back to the beginning. */ { apr_off_t offset = 0; rv = apr_file_seek(f, APR_SET, &offset); } apr_file_read_full(f, buf, sizeof(buf), NULL); ABTS_STR_EQUAL(tc, "helloworld", buf); apr_file_close(f); } abts_suite *testfile(abts_suite *suite) { suite = ADD_SUITE(suite) abts_run_test(suite, test_open_noreadwrite, NULL); abts_run_test(suite, test_open_excl, NULL); abts_run_test(suite, test_open_read, NULL); abts_run_test(suite, test_open_readwrite, NULL); abts_run_test(suite, test_read, NULL); abts_run_test(suite, test_readzero, NULL); abts_run_test(suite, test_seek, NULL); abts_run_test(suite, test_filename, NULL); abts_run_test(suite, test_fileclose, NULL); abts_run_test(suite, test_file_remove, NULL); abts_run_test(suite, test_open_write, NULL); abts_run_test(suite, test_open_writecreate, NULL); abts_run_test(suite, test_write, NULL); abts_run_test(suite, test_userdata_set, NULL); abts_run_test(suite, test_userdata_get, NULL); abts_run_test(suite, test_userdata_getnokey, NULL); abts_run_test(suite, test_getc, NULL); abts_run_test(suite, test_ungetc, NULL); abts_run_test(suite, test_gets, NULL); abts_run_test(suite, test_puts, NULL); abts_run_test(suite, test_writev, NULL); abts_run_test(suite, test_writev_full, NULL); abts_run_test(suite, test_bigread, NULL); abts_run_test(suite, test_mod_neg, NULL); abts_run_test(suite, test_truncate, NULL); abts_run_test(suite, test_bigfprintf, NULL); abts_run_test(suite, test_fail_write_flush, NULL); abts_run_test(suite, test_fail_read_flush, NULL); abts_run_test(suite, test_xthread, NULL); return suite; }
001-log4cxx
trunk/src/apr/test/testfile.c
C
asf20
26,220
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef TESTFLOCK #define TESTFLOCK #define TESTFILE "data/testfile.lock" #define FAILED_READ 0 #define SUCCESSFUL_READ 1 #define UNEXPECTED_ERROR 2 #endif
001-log4cxx
trunk/src/apr/test/testflock.h
C
asf20
966
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "apr_network_io.h" #include "apr_errno.h" #include "apr_general.h" #include "apr_lib.h" #include "testutil.h" #define STRLEN 21 static void tcp_socket(abts_case *tc, void *data) { apr_status_t rv; apr_socket_t *sock = NULL; int type; rv = apr_socket_create(&sock, APR_INET, SOCK_STREAM, 0, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_PTR_NOTNULL(tc, sock); rv = apr_socket_type_get(sock, &type); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, SOCK_STREAM, type); apr_socket_close(sock); } static void udp_socket(abts_case *tc, void *data) { apr_status_t rv; apr_socket_t *sock = NULL; int type; rv = apr_socket_create(&sock, APR_INET, SOCK_DGRAM, 0, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_PTR_NOTNULL(tc, sock); rv = apr_socket_type_get(sock, &type); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, SOCK_DGRAM, type); apr_socket_close(sock); } /* On recent Linux systems, whilst IPv6 is always supported by glibc, * socket(AF_INET6, ...) calls will fail with EAFNOSUPPORT if the * "ipv6" kernel module is not loaded. */ #ifdef EAFNOSUPPORT #define V6_NOT_ENABLED(e) ((e) == EAFNOSUPPORT) #else #define V6_NOT_ENABLED(e) (0) #endif static void tcp6_socket(abts_case *tc, void *data) { #if APR_HAVE_IPV6 apr_status_t rv; apr_socket_t *sock = NULL; rv = apr_socket_create(&sock, APR_INET6, SOCK_STREAM, 0, p); if (V6_NOT_ENABLED(rv)) { ABTS_NOT_IMPL(tc, "IPv6 not enabled"); return; } ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_PTR_NOTNULL(tc, sock); apr_socket_close(sock); #else ABTS_NOT_IMPL(tc, "IPv6"); #endif } static void udp6_socket(abts_case *tc, void *data) { #if APR_HAVE_IPV6 apr_status_t rv; apr_socket_t *sock = NULL; rv = apr_socket_create(&sock, APR_INET6, SOCK_DGRAM, 0, p); if (V6_NOT_ENABLED(rv)) { ABTS_NOT_IMPL(tc, "IPv6 not enabled"); return; } ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_PTR_NOTNULL(tc, sock); apr_socket_close(sock); #else ABTS_NOT_IMPL(tc, "IPv6"); #endif } static void sendto_receivefrom(abts_case *tc, void *data) { apr_status_t rv; apr_socket_t *sock = NULL; apr_socket_t *sock2 = NULL; char sendbuf[STRLEN] = "APR_INET, SOCK_DGRAM"; char recvbuf[80]; char *ip_addr; apr_port_t fromport; apr_sockaddr_t *from; apr_sockaddr_t *to; apr_size_t len = 30; int family; const char *addr; #if APR_HAVE_IPV6 family = APR_INET6; addr = "::1"; rv = apr_socket_create(&sock, family, SOCK_DGRAM, 0, p); if (V6_NOT_ENABLED(rv)) { #endif family = APR_INET; addr = "127.0.0.1"; rv = apr_socket_create(&sock, family, SOCK_DGRAM, 0, p); #if APR_HAVE_IPV6 } #endif ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_socket_create(&sock2, family, SOCK_DGRAM, 0, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_sockaddr_info_get(&to, addr, APR_UNSPEC, 7772, 0, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_sockaddr_info_get(&from, addr, APR_UNSPEC, 7771, 0, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_socket_opt_set(sock, APR_SO_REUSEADDR, 1); APR_ASSERT_SUCCESS(tc, "Could not set REUSEADDR on socket", rv); rv = apr_socket_opt_set(sock2, APR_SO_REUSEADDR, 1); APR_ASSERT_SUCCESS(tc, "Could not set REUSEADDR on socket2", rv); rv = apr_socket_bind(sock, to); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_socket_bind(sock2, from); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); len = STRLEN; rv = apr_socket_sendto(sock2, to, 0, sendbuf, &len); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, STRLEN, len); len = 80; rv = apr_socket_recvfrom(from, sock, 0, recvbuf, &len); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, STRLEN, len); ABTS_STR_EQUAL(tc, "APR_INET, SOCK_DGRAM", recvbuf); apr_sockaddr_ip_get(&ip_addr, from); fromport = from->port; ABTS_STR_EQUAL(tc, addr, ip_addr); ABTS_INT_EQUAL(tc, 7771, fromport); apr_socket_close(sock); apr_socket_close(sock2); } static void socket_userdata(abts_case *tc, void *data) { apr_socket_t *sock1, *sock2; apr_status_t rv; void *user; const char *key = "GENERICKEY"; rv = apr_socket_create(&sock1, AF_INET, SOCK_STREAM, 0, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_socket_create(&sock2, AF_INET, SOCK_STREAM, 0, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_socket_data_set(sock1, "SOCK1", key, NULL); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_socket_data_set(sock2, "SOCK2", key, NULL); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_socket_data_get(&user, key, sock1); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_STR_EQUAL(tc, "SOCK1", user); rv = apr_socket_data_get(&user, key, sock2); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_STR_EQUAL(tc, "SOCK2", user); } abts_suite *testsockets(abts_suite *suite) { suite = ADD_SUITE(suite) abts_run_test(suite, tcp_socket, NULL); abts_run_test(suite, udp_socket, NULL); abts_run_test(suite, tcp6_socket, NULL); abts_run_test(suite, udp6_socket, NULL); abts_run_test(suite, sendto_receivefrom, NULL); abts_run_test(suite, socket_userdata, NULL); return suite; }
001-log4cxx
trunk/src/apr/test/testsockets.c
C
asf20
6,179
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef APR_TEST_INCLUDES #define APR_TEST_INCLUDES #include "abts.h" #include "testutil.h" const struct testlist { abts_suite *(*func)(abts_suite *suite); } alltests[] = { {testatomic}, {testdir}, {testdso}, {testdup}, {testenv}, {testfile}, {testfilecopy}, {testfileinfo}, {testflock}, {testfmt}, {testfnmatch}, {testgetopt}, #if 0 /* not ready yet due to API issues */ {testglobalmutex}, #endif {testhash}, {testipsub}, {testlock}, {testlfs}, {testmmap}, {testnames}, {testoc}, {testpath}, {testpipe}, {testpoll}, {testpool}, {testproc}, {testprocmutex}, {testrand}, {testrand2}, {testsleep}, {testshm}, {testsock}, {testsockets}, {testsockopt}, {teststr}, {teststrnatcmp}, {testtable}, {testtemp}, {testthread}, {testtime}, {testud}, {testuser}, {testvsn} }; #endif /* APR_TEST_INCLUDES */
001-log4cxx
trunk/src/apr/test/abts_tests.h
C
asf20
1,769
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "testutil.h" #include <assert.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #if APR_HAVE_LIMITS_H #include <limits.h> #endif #include "apr_general.h" #include "apr_strings.h" #include "apr_errno.h" /* I haven't bothered to check for APR_ENOTIMPL here, AFAIK, all string * functions exist on all platforms. */ static void test_strtok(abts_case *tc, void *data) { struct { char *input; char *sep; } cases[] = { { "", "Z" }, { " asdf jkl; 77889909 \r\n\1\2\3Z", " \r\n\3\2\1" }, { NULL, /* but who cares if apr_strtok() segfaults? */ " \t" }, #if 0 /* don't do this... you deserve to segfault */ { "a b c ", NULL }, #endif { " a b c ", "" }, { "a b c ", " " } }; int curtc; for (curtc = 0; curtc < sizeof cases / sizeof cases[0]; curtc++) { char *retval1, *retval2; char *str1, *str2; char *state; str1 = apr_pstrdup(p, cases[curtc].input); str2 = apr_pstrdup(p, cases[curtc].input); do { retval1 = apr_strtok(str1, cases[curtc].sep, &state); retval2 = strtok(str2, cases[curtc].sep); if (!retval1) { ABTS_TRUE(tc, retval2 == NULL); } else { ABTS_TRUE(tc, retval2 != NULL); ABTS_STR_EQUAL(tc, retval2, retval1); } str1 = str2 = NULL; /* make sure we pass NULL on subsequent calls */ } while (retval1); } } static void snprintf_noNULL(abts_case *tc, void *data) { char buff[100]; char *testing = apr_palloc(p, 10); testing[0] = 't'; testing[1] = 'e'; testing[2] = 's'; testing[3] = 't'; testing[4] = 'i'; testing[5] = 'n'; testing[6] = 'g'; /* If this test fails, we are going to seg fault. */ apr_snprintf(buff, sizeof(buff), "%.*s", 7, testing); ABTS_STR_NEQUAL(tc, buff, testing, 7); } static void snprintf_0NULL(abts_case *tc, void *data) { int rv; rv = apr_snprintf(NULL, 0, "%sBAR", "FOO"); ABTS_INT_EQUAL(tc, 6, rv); } static void snprintf_0nonNULL(abts_case *tc, void *data) { int rv; char *buff = "testing"; rv = apr_snprintf(buff, 0, "%sBAR", "FOO"); ABTS_INT_EQUAL(tc, 6, rv); ABTS_ASSERT(tc, "buff unmangled", strcmp(buff, "FOOBAR") != 0); } static void snprintf_underflow(abts_case *tc, void *data) { char buf[20]; int rv; rv = apr_snprintf(buf, sizeof buf, "%.2f", (double)0.0001); ABTS_INT_EQUAL(tc, 4, rv); ABTS_STR_EQUAL(tc, "0.00", buf); rv = apr_snprintf(buf, sizeof buf, "%.2f", (double)0.001); ABTS_INT_EQUAL(tc, 4, rv); ABTS_STR_EQUAL(tc, "0.00", buf); rv = apr_snprintf(buf, sizeof buf, "%.2f", (double)0.01); ABTS_INT_EQUAL(tc, 4, rv); ABTS_STR_EQUAL(tc, "0.01", buf); } static void string_error(abts_case *tc, void *data) { char buf[128], *rv; apr_status_t n; buf[0] = '\0'; rv = apr_strerror(APR_ENOENT, buf, sizeof buf); ABTS_PTR_EQUAL(tc, buf, rv); ABTS_TRUE(tc, strlen(buf) > 0); rv = apr_strerror(APR_TIMEUP, buf, sizeof buf); ABTS_PTR_EQUAL(tc, buf, rv); ABTS_STR_EQUAL(tc, "The timeout specified has expired", buf); /* throw some randomish numbers at it to check for robustness */ for (n = 1; n < 1000000; n *= 2) { apr_strerror(n, buf, sizeof buf); } } #define SIZE 180000 static void string_long(abts_case *tc, void *data) { char s[SIZE + 1]; memset(s, 'A', SIZE); s[SIZE] = '\0'; apr_psprintf(p, "%s", s); } /* ### FIXME: apr.h/apr_strings.h should provide these! */ #define MY_LLONG_MAX (APR_INT64_C(9223372036854775807)) #define MY_LLONG_MIN (-MY_LLONG_MAX - APR_INT64_C(1)) static void string_strtoi64(abts_case *tc, void *data) { static const struct { int errnum, base; const char *in, *end; apr_int64_t result; } ts[] = { /* base 10 tests */ { 0, 10, "123545", NULL, APR_INT64_C(123545) }, { 0, 10, " 123545", NULL, APR_INT64_C(123545) }, { 0, 10, " +123545", NULL, APR_INT64_C(123545) }, { 0, 10, "-123545", NULL, APR_INT64_C(-123545) }, { 0, 10, " 00000123545", NULL, APR_INT64_C(123545) }, { 0, 10, "123545ZZZ", "ZZZ", APR_INT64_C(123545) }, { 0, 10, " 123545 ", " ", APR_INT64_C(123545) }, /* base 16 tests */ { 0, 16, "1E299", NULL, APR_INT64_C(123545) }, { 0, 16, "1e299", NULL, APR_INT64_C(123545) }, { 0, 16, "0x1e299", NULL, APR_INT64_C(123545) }, { 0, 16, "0X1E299", NULL, APR_INT64_C(123545) }, { 0, 16, "+1e299", NULL, APR_INT64_C(123545) }, { 0, 16, "-1e299", NULL, APR_INT64_C(-123545) }, { 0, 16, " -1e299", NULL, APR_INT64_C(-123545) }, /* automatic base detection tests */ { 0, 0, "123545", NULL, APR_INT64_C(123545) }, { 0, 0, "0x1e299", NULL, APR_INT64_C(123545) }, { 0, 0, " 0x1e299", NULL, APR_INT64_C(123545) }, { 0, 0, "+0x1e299", NULL, APR_INT64_C(123545) }, { 0, 0, "-0x1e299", NULL, APR_INT64_C(-123545) }, /* large number tests */ { 0, 10, "8589934605", NULL, APR_INT64_C(8589934605) }, { 0, 10, "-8589934605", NULL, APR_INT64_C(-8589934605) }, { 0, 16, "0x20000000D", NULL, APR_INT64_C(8589934605) }, { 0, 16, "-0x20000000D", NULL, APR_INT64_C(-8589934605) }, { 0, 16, " 0x20000000D", NULL, APR_INT64_C(8589934605) }, { 0, 16, " 0x20000000D", NULL, APR_INT64_C(8589934605) }, /* error cases */ { ERANGE, 10, "999999999999999999999999999999999", "", MY_LLONG_MAX }, { ERANGE, 10, "-999999999999999999999999999999999", "", MY_LLONG_MIN }, #if 0 /* C99 doesn't require EINVAL for an invalid range. */ { EINVAL, 99, "", (void *)-1 /* don't care */, 0 }, #endif /* some strtoll implementations give EINVAL when no conversion * is performed. */ { -1 /* don't care */, 10, "zzz", "zzz", APR_INT64_C(0) }, { -1 /* don't care */, 10, "", NULL, APR_INT64_C(0) } }; int n; for (n = 0; n < sizeof(ts)/sizeof(ts[0]); n++) { char *end = "end ptr not changed"; apr_int64_t result; int errnum; errno = 0; result = apr_strtoi64(ts[n].in, &end, ts[n].base); errnum = errno; ABTS_ASSERT(tc, apr_psprintf(p, "for '%s': result was %" APR_INT64_T_FMT " not %" APR_INT64_T_FMT, ts[n].in, result, ts[n].result), result == ts[n].result); if (ts[n].errnum != -1) { ABTS_ASSERT(tc, apr_psprintf(p, "for '%s': errno was %d not %d", ts[n].in, errnum, ts[n].errnum), ts[n].errnum == errnum); } if (ts[n].end == NULL) { /* end must point to NUL terminator of .in */ ABTS_PTR_EQUAL(tc, ts[n].in + strlen(ts[n].in), end); } else if (ts[n].end != (void *)-1) { ABTS_ASSERT(tc, apr_psprintf(p, "for '%s', end was '%s' not '%s'", ts[n].in, end, ts[n].end), strcmp(ts[n].end, end) == 0); } } } static void string_strtoff(abts_case *tc, void *data) { apr_off_t off; ABTS_ASSERT(tc, "strtoff fails on out-of-range integer", apr_strtoff(&off, "999999999999999999999999999999", NULL, 10) != APR_SUCCESS); ABTS_ASSERT(tc, "strtoff failed for 1234", apr_strtoff(&off, "1234", NULL, 10) == APR_SUCCESS); ABTS_ASSERT(tc, "strtoff failed to parse 1234", off == 1234); } /* random-ish checks for strfsize buffer overflows */ static void overflow_strfsize(abts_case *tc, void *data) { apr_off_t off; char buf[7]; buf[5] = '$'; buf[6] = '@'; for (off = -9999; off < 20000; off++) { apr_strfsize(off, buf); } for (; off < 9999999; off += 9) { apr_strfsize(off, buf); } for (; off < 999999999; off += 999) { apr_strfsize(off, buf); } for (off = 1; off < LONG_MAX && off > 0; off *= 2) { apr_strfsize(off, buf); apr_strfsize(off + 1, buf); apr_strfsize(off - 1, buf); } ABTS_ASSERT(tc, "strfsize overflowed", buf[5] == '$'); ABTS_ASSERT(tc, "strfsize overflowed", buf[6] == '@'); } static void string_strfsize(abts_case *tc, void *data) { static const struct { apr_off_t size; const char *buf; } ts[] = { { -1, " - " }, { 0, " 0 " }, { 666, "666 " }, { 1024, "1.0K" }, { 1536, "1.5K" }, { 2048, "2.0K" }, { 1293874, "1.2M" }, { 9999999, "9.5M" }, { 103809024, " 99M" }, { 1047527424, "1.0G" } /* "999M" would be more correct */ }; apr_size_t n; for (n = 0; n < sizeof(ts)/sizeof(ts[0]); n++) { char buf[6], *ret; buf[5] = '%'; ret = apr_strfsize(ts[n].size, buf); ABTS_ASSERT(tc, "strfsize returned wrong buffer", ret == buf); ABTS_ASSERT(tc, "strfsize overflowed", buf[5] == '%'); ABTS_STR_EQUAL(tc, ts[n].buf, ret); } } static void snprintf_overflow(abts_case *tc, void *data) { char buf[4]; int rv; buf[2] = '4'; buf[3] = '2'; rv = apr_snprintf(buf, 2, "%s", "a"); ABTS_INT_EQUAL(tc, 1, rv); rv = apr_snprintf(buf, 2, "%s", "abcd"); ABTS_INT_EQUAL(tc, 1, rv); ABTS_STR_EQUAL(tc, buf, "a"); /* Check the buffer really hasn't been overflowed. */ ABTS_TRUE(tc, buf[2] == '4' && buf[3] == '2'); } abts_suite *teststr(abts_suite *suite) { suite = ADD_SUITE(suite) abts_run_test(suite, snprintf_0NULL, NULL); abts_run_test(suite, snprintf_0nonNULL, NULL); abts_run_test(suite, snprintf_noNULL, NULL); abts_run_test(suite, snprintf_underflow, NULL); abts_run_test(suite, test_strtok, NULL); abts_run_test(suite, string_error, NULL); abts_run_test(suite, string_long, NULL); abts_run_test(suite, string_strtoi64, NULL); abts_run_test(suite, string_strtoff, NULL); abts_run_test(suite, overflow_strfsize, NULL); abts_run_test(suite, string_strfsize, NULL); abts_run_test(suite, snprintf_overflow, NULL); return suite; }
001-log4cxx
trunk/src/apr/test/teststr.c
C
asf20
11,544
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "testutil.h" #include "apr.h" #include "apr_strings.h" #include "apr_general.h" #include "apr_pools.h" #include "apr_tables.h" #if APR_HAVE_STDIO_H #include <stdio.h> #endif #if APR_HAVE_STDLIB_H #include <stdlib.h> #endif #if APR_HAVE_STRING_H #include <string.h> #endif static apr_table_t *t1 = NULL; static void table_make(abts_case *tc, void *data) { t1 = apr_table_make(p, 5); ABTS_PTR_NOTNULL(tc, t1); } static void table_get(abts_case *tc, void *data) { const char *val; apr_table_set(t1, "foo", "bar"); val = apr_table_get(t1, "foo"); ABTS_STR_EQUAL(tc, val, "bar"); } static void table_set(abts_case *tc, void *data) { const char *val; apr_table_set(t1, "setkey", "bar"); apr_table_set(t1, "setkey", "2ndtry"); val = apr_table_get(t1, "setkey"); ABTS_STR_EQUAL(tc, val, "2ndtry"); } static void table_getnotthere(abts_case *tc, void *data) { const char *val; val = apr_table_get(t1, "keynotthere"); ABTS_PTR_EQUAL(tc, NULL, (void *)val); } static void table_add(abts_case *tc, void *data) { const char *val; apr_table_add(t1, "addkey", "bar"); apr_table_add(t1, "addkey", "foo"); val = apr_table_get(t1, "addkey"); ABTS_STR_EQUAL(tc, val, "bar"); } static void table_nelts(abts_case *tc, void *data) { const char *val; apr_table_t *t = apr_table_make(p, 1); apr_table_set(t, "abc", "def"); apr_table_set(t, "def", "abc"); apr_table_set(t, "foo", "zzz"); val = apr_table_get(t, "foo"); ABTS_STR_EQUAL(tc, val, "zzz"); val = apr_table_get(t, "abc"); ABTS_STR_EQUAL(tc, val, "def"); val = apr_table_get(t, "def"); ABTS_STR_EQUAL(tc, val, "abc"); ABTS_INT_EQUAL(tc, 3, apr_table_elts(t)->nelts); } static void table_clear(abts_case *tc, void *data) { apr_table_clear(t1); ABTS_INT_EQUAL(tc, 0, apr_table_elts(t1)->nelts); } static void table_unset(abts_case *tc, void *data) { const char *val; apr_table_t *t = apr_table_make(p, 1); apr_table_set(t, "a", "1"); apr_table_set(t, "b", "2"); apr_table_unset(t, "b"); ABTS_INT_EQUAL(tc, 1, apr_table_elts(t)->nelts); val = apr_table_get(t, "a"); ABTS_STR_EQUAL(tc, val, "1"); val = apr_table_get(t, "b"); ABTS_PTR_EQUAL(tc, (void *)val, (void *)NULL); } static void table_overlap(abts_case *tc, void *data) { const char *val; apr_table_t *t1 = apr_table_make(p, 1); apr_table_t *t2 = apr_table_make(p, 1); apr_table_addn(t1, "a", "0"); apr_table_addn(t1, "g", "7"); apr_table_addn(t2, "a", "1"); apr_table_addn(t2, "b", "2"); apr_table_addn(t2, "c", "3"); apr_table_addn(t2, "b", "2.0"); apr_table_addn(t2, "d", "4"); apr_table_addn(t2, "e", "5"); apr_table_addn(t2, "b", "2."); apr_table_addn(t2, "f", "6"); apr_table_overlap(t1, t2, APR_OVERLAP_TABLES_SET); ABTS_INT_EQUAL(tc, apr_table_elts(t1)->nelts, 7); val = apr_table_get(t1, "a"); ABTS_STR_EQUAL(tc, val, "1"); val = apr_table_get(t1, "b"); ABTS_STR_EQUAL(tc, val, "2."); val = apr_table_get(t1, "c"); ABTS_STR_EQUAL(tc, val, "3"); val = apr_table_get(t1, "d"); ABTS_STR_EQUAL(tc, val, "4"); val = apr_table_get(t1, "e"); ABTS_STR_EQUAL(tc, val, "5"); val = apr_table_get(t1, "f"); ABTS_STR_EQUAL(tc, val, "6"); val = apr_table_get(t1, "g"); ABTS_STR_EQUAL(tc, val, "7"); } static void table_overlap2(abts_case *tc, void *data) { apr_pool_t *subp; apr_table_t *t1, *t2; apr_pool_create(&subp, p); t1 = apr_table_make(subp, 1); t2 = apr_table_make(p, 1); apr_table_addn(t1, "t1", "one"); apr_table_addn(t2, "t2", "two"); apr_table_overlap(t1, t2, APR_OVERLAP_TABLES_SET); ABTS_INT_EQUAL(tc, 2, apr_table_elts(t1)->nelts); ABTS_STR_EQUAL(tc, apr_table_get(t1, "t1"), "one"); ABTS_STR_EQUAL(tc, apr_table_get(t1, "t2"), "two"); } abts_suite *testtable(abts_suite *suite) { suite = ADD_SUITE(suite) abts_run_test(suite, table_make, NULL); abts_run_test(suite, table_get, NULL); abts_run_test(suite, table_set, NULL); abts_run_test(suite, table_getnotthere, NULL); abts_run_test(suite, table_add, NULL); abts_run_test(suite, table_nelts, NULL); abts_run_test(suite, table_clear, NULL); abts_run_test(suite, table_unset, NULL); abts_run_test(suite, table_overlap, NULL); abts_run_test(suite, table_overlap2, NULL); return suite; }
001-log4cxx
trunk/src/apr/test/testtable.c
C
asf20
5,270
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "apr_general.h" #include "apr_random.h" #include "apr_thread_proc.h" #include <errno.h> #include <stdio.h> #include <stdlib.h> #include "testutil.h" static void hexdump(const unsigned char *b,int n) { int i; for(i=0 ; i < n ; ++i) { #if 0 if((i&0xf) == 0) printf("%04x",i); printf(" %02x",b[i]); if((i&0xf) == 0xf) printf("\n"); #else printf("0x%02x,",b[i]); if((i&7) == 7) printf("\n"); #endif } printf("\n"); } static apr_random_t *r; typedef apr_status_t APR_THREAD_FUNC rnd_fn(apr_random_t *r,void *b,apr_size_t n); static void rand_run_kat(abts_case *tc,rnd_fn *f,apr_random_t *r, const unsigned char expected[128]) { unsigned char c[128]; apr_status_t rv; rv=f(r,c,128); ABTS_INT_EQUAL(tc,0,rv); if(rv) return; if(memcmp(c,expected,128)) { hexdump(c,128); hexdump(expected,128); ABTS_FAIL(tc,"Randomness mismatch"); } } static int rand_check_kat(rnd_fn *f,apr_random_t *r, const unsigned char expected[128]) { unsigned char c[128]; apr_status_t rv; rv=f(r,c,128); if(rv) return 2; if(memcmp(c,expected,128)) return 1; return 0; } static void rand_add_zeroes(apr_random_t *r) { static unsigned char c[2048]; apr_random_add_entropy(r,c,sizeof c); } static void rand_run_seed_short(abts_case *tc,rnd_fn *f,apr_random_t *r, int count) { int i; apr_status_t rv; char c[1]; for(i=0 ; i < count ; ++i) rand_add_zeroes(r); rv=f(r,c,1); ABTS_INT_EQUAL(tc,1,APR_STATUS_IS_ENOTENOUGHENTROPY(rv)); } static void rand_seed_short(abts_case *tc, void *data) { r=apr_random_standard_new(p); rand_run_seed_short(tc,apr_random_insecure_bytes,r,32); } static void rand_kat(abts_case *tc, void *data) { unsigned char expected[128]= { 0x82,0x04,0xad,0xd2,0x0b,0xd5,0xac,0xda, 0x3d,0x85,0x58,0x38,0x54,0x6b,0x69,0x45, 0x37,0x4c,0xc7,0xd7,0x87,0xeb,0xbf,0xd9, 0xb1,0xb8,0xb8,0x2d,0x9b,0x33,0x6e,0x97, 0x04,0x1d,0x4c,0xb0,0xd1,0xdf,0x3d,0xac, 0xd2,0xaa,0xfa,0xcd,0x96,0xb7,0xcf,0xb1, 0x8e,0x3d,0xb3,0xe5,0x37,0xa9,0x95,0xb4, 0xaa,0x3d,0x11,0x1a,0x08,0x20,0x21,0x9f, 0xdb,0x08,0x3a,0xb9,0x57,0x9f,0xf2,0x1f, 0x27,0xdc,0xb6,0xc0,0x85,0x08,0x05,0xbb, 0x13,0xbe,0xb1,0xe9,0x63,0x2a,0xe2,0xa4, 0x23,0x15,0x2a,0x10,0xbf,0xdf,0x09,0xb3, 0xc7,0xfb,0x2d,0x87,0x48,0x19,0xfb,0xc0, 0x15,0x8c,0xcb,0xc6,0xbd,0x89,0x38,0x69, 0xa3,0xae,0xa3,0x21,0x58,0x50,0xe7,0xc4, 0x87,0xec,0x2e,0xb1,0x2d,0x6a,0xbd,0x46 }; rand_add_zeroes(r); rand_run_kat(tc,apr_random_insecure_bytes,r,expected); } static void rand_seed_short2(abts_case *tc, void *data) { rand_run_seed_short(tc,apr_random_secure_bytes,r,320); } static void rand_kat2(abts_case *tc, void *data) { unsigned char expected[128]= { 0x38,0x8f,0x01,0x29,0x5a,0x5c,0x1f,0xa8, 0x00,0xde,0x16,0x4c,0xe5,0xf7,0x1f,0x58, 0xc0,0x67,0xe2,0x98,0x3d,0xde,0x4a,0x75, 0x61,0x3f,0x23,0xd8,0x45,0x7a,0x10,0x60, 0x59,0x9b,0xd6,0xaf,0xcb,0x0a,0x2e,0x34, 0x9c,0x39,0x5b,0xd0,0xbc,0x9a,0xf0,0x7b, 0x7f,0x40,0x8b,0x33,0xc0,0x0e,0x2a,0x56, 0xfc,0xe5,0xab,0xde,0x7b,0x13,0xf5,0xec, 0x15,0x68,0xb8,0x09,0xbc,0x2c,0x15,0xf0, 0x7b,0xef,0x2a,0x97,0x19,0xa8,0x69,0x51, 0xdf,0xb0,0x5f,0x1a,0x4e,0xdf,0x42,0x02, 0x71,0x36,0xa7,0x25,0x64,0x85,0xe2,0x72, 0xc7,0x87,0x4d,0x7d,0x15,0xbb,0x15,0xd1, 0xb1,0x62,0x0b,0x25,0xd9,0xd3,0xd9,0x5a, 0xe3,0x47,0x1e,0xae,0x67,0xb4,0x19,0x9e, 0xed,0xd2,0xde,0xce,0x18,0x70,0x57,0x12 }; rand_add_zeroes(r); rand_run_kat(tc,apr_random_secure_bytes,r,expected); } static void rand_barrier(abts_case *tc, void *data) { apr_random_barrier(r); rand_run_seed_short(tc,apr_random_secure_bytes,r,320); } static void rand_kat3(abts_case *tc, void *data) { unsigned char expected[128]= { 0xe8,0xe7,0xc9,0x45,0xe2,0x2a,0x54,0xb2, 0xdd,0xe0,0xf9,0xbc,0x3d,0xf9,0xce,0x3c, 0x4c,0xbd,0xc9,0xe2,0x20,0x4a,0x35,0x1c, 0x04,0x52,0x7f,0xb8,0x0f,0x60,0x89,0x63, 0x8a,0xbe,0x0a,0x44,0xac,0x5d,0xd8,0xeb, 0x24,0x7d,0xd1,0xda,0x4d,0x86,0x9b,0x94, 0x26,0x56,0x4a,0x5e,0x30,0xea,0xd4,0xa9, 0x9a,0xdf,0xdd,0xb6,0xb1,0x15,0xe0,0xfa, 0x28,0xa4,0xd6,0x95,0xa4,0xf1,0xd8,0x6e, 0xeb,0x8c,0xa4,0xac,0x34,0xfe,0x06,0x92, 0xc5,0x09,0x99,0x86,0xdc,0x5a,0x3c,0x92, 0xc8,0x3e,0x52,0x00,0x4d,0x01,0x43,0x6f, 0x69,0xcf,0xe2,0x60,0x9c,0x23,0xb3,0xa5, 0x5f,0x51,0x47,0x8c,0x07,0xde,0x60,0xc6, 0x04,0xbf,0x32,0xd6,0xdc,0xb7,0x31,0x01, 0x29,0x51,0x51,0xb3,0x19,0x6e,0xe4,0xf8 }; rand_run_kat(tc,apr_random_insecure_bytes,r,expected); } static void rand_kat4(abts_case *tc, void *data) { unsigned char expected[128]= { 0x7d,0x0e,0xc4,0x4e,0x3e,0xac,0x86,0x50, 0x37,0x95,0x7a,0x98,0x23,0x26,0xa7,0xbf, 0x60,0xfb,0xa3,0x70,0x90,0xc3,0x58,0xc6, 0xbd,0xd9,0x5e,0xa6,0x77,0x62,0x7a,0x5c, 0x96,0x83,0x7f,0x80,0x3d,0xf4,0x9c,0xcc, 0x9b,0x0c,0x8c,0xe1,0x72,0xa8,0xfb,0xc9, 0xc5,0x43,0x91,0xdc,0x9d,0x92,0xc2,0xce, 0x1c,0x5e,0x36,0xc7,0x87,0xb1,0xb4,0xa3, 0xc8,0x69,0x76,0xfc,0x35,0x75,0xcb,0x08, 0x2f,0xe3,0x98,0x76,0x37,0x80,0x04,0x5c, 0xb8,0xb0,0x7f,0xb2,0xda,0xe3,0xa3,0xba, 0xed,0xff,0xf5,0x9d,0x3b,0x7b,0xf3,0x32, 0x6c,0x50,0xa5,0x3e,0xcc,0xe1,0x84,0x9c, 0x17,0x9e,0x80,0x64,0x09,0xbb,0x62,0xf1, 0x95,0xf5,0x2c,0xc6,0x9f,0x6a,0xee,0x6d, 0x17,0x35,0x5f,0x35,0x8d,0x55,0x0c,0x07 }; rand_add_zeroes(r); rand_run_kat(tc,apr_random_secure_bytes,r,expected); } #if APR_HAS_FORK static void rand_fork(abts_case *tc, void *data) { apr_proc_t proc; apr_status_t rv; unsigned char expected[128]= { 0xac,0x93,0xd2,0x5c,0xc7,0xf5,0x8d,0xc2, 0xd8,0x8d,0xb6,0x7a,0x94,0xe1,0x83,0x4c, 0x26,0xe2,0x38,0x6d,0xf5,0xbd,0x9d,0x6e, 0x91,0x77,0x3a,0x4b,0x9b,0xef,0x9b,0xa3, 0x9f,0xf6,0x6d,0x0c,0xdc,0x4b,0x02,0xe9, 0x5d,0x3d,0xfc,0x92,0x6b,0xdf,0xc9,0xef, 0xb9,0xa8,0x74,0x09,0xa3,0xff,0x64,0x8d, 0x19,0xc1,0x31,0x31,0x17,0xe1,0xb7,0x7a, 0xe7,0x55,0x14,0x92,0x05,0xe3,0x1e,0xb8, 0x9b,0x1b,0xdc,0xac,0x0e,0x15,0x08,0xa2, 0x93,0x13,0xf6,0x04,0xc6,0x9d,0xf8,0x7f, 0x26,0x32,0x68,0x43,0x2e,0x5a,0x4f,0x47, 0xe8,0xf8,0x59,0xb7,0xfb,0xbe,0x30,0x04, 0xb6,0x63,0x6f,0x19,0xf3,0x2c,0xd4,0xeb, 0x32,0x8a,0x54,0x01,0xd0,0xaf,0x3f,0x13, 0xc1,0x7f,0x10,0x2e,0x08,0x1c,0x28,0x4b, }; rv=apr_proc_fork(&proc,p); if(rv == APR_INCHILD) { int n; n=rand_check_kat(apr_random_secure_bytes,r,expected); exit(n); } else if(rv == APR_INPARENT) { int exitcode; apr_exit_why_e why; rand_run_kat(tc,apr_random_secure_bytes,r,expected); apr_proc_wait(&proc,&exitcode,&why,APR_WAIT); if(why != APR_PROC_EXIT) { ABTS_FAIL(tc,"Child terminated abnormally"); return; } if(exitcode == 0) { ABTS_FAIL(tc,"Child produced our randomness"); return; } else if(exitcode == 2) { ABTS_FAIL(tc,"Child randomness failed"); return; } else if(exitcode != 1) { ABTS_FAIL(tc,"Uknown child error"); return; } } else { ABTS_FAIL(tc,"Fork failed"); return; } } #endif abts_suite *testrand2(abts_suite *suite) { suite = ADD_SUITE(suite) abts_run_test(suite, rand_seed_short, NULL); abts_run_test(suite, rand_kat, NULL); abts_run_test(suite, rand_seed_short2, NULL); abts_run_test(suite, rand_kat2, NULL); abts_run_test(suite, rand_barrier, NULL); abts_run_test(suite, rand_kat3, NULL); abts_run_test(suite, rand_kat4, NULL); #if APR_HAS_FORK abts_run_test(suite, rand_fork, NULL); #endif return suite; }
001-log4cxx
trunk/src/apr/test/testrand2.c
C
asf20
9,508
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <stdlib.h> #include "testutil.h" #include "apr_file_io.h" #include "apr_errno.h" #include "apr_general.h" #include "apr_lib.h" #include "apr_thread_proc.h" #include "apr_strings.h" static apr_file_t *readp = NULL; static apr_file_t *writep = NULL; static void create_pipe(abts_case *tc, void *data) { apr_status_t rv; rv = apr_file_pipe_create(&readp, &writep, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_PTR_NOTNULL(tc, readp); ABTS_PTR_NOTNULL(tc, writep); } static void close_pipe(abts_case *tc, void *data) { apr_status_t rv; apr_size_t nbytes = 256; char buf[256]; rv = apr_file_close(readp); rv = apr_file_close(writep); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_file_read(readp, buf, &nbytes); ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_EBADF(rv)); } static void set_timeout(abts_case *tc, void *data) { apr_status_t rv; apr_interval_time_t timeout; rv = apr_file_pipe_create(&readp, &writep, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_PTR_NOTNULL(tc, readp); ABTS_PTR_NOTNULL(tc, writep); rv = apr_file_pipe_timeout_get(readp, &timeout); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_ASSERT(tc, "Timeout mismatch, expected -1", timeout == -1); rv = apr_file_pipe_timeout_set(readp, apr_time_from_sec(1)); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_file_pipe_timeout_get(readp, &timeout); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_ASSERT(tc, "Timeout mismatch, expected 1 second", timeout == apr_time_from_sec(1)); } static void read_write(abts_case *tc, void *data) { apr_status_t rv; char *buf; apr_size_t nbytes; nbytes = strlen("this is a test"); buf = (char *)apr_palloc(p, nbytes + 1); rv = apr_file_pipe_create(&readp, &writep, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_PTR_NOTNULL(tc, readp); ABTS_PTR_NOTNULL(tc, writep); rv = apr_file_pipe_timeout_set(readp, apr_time_from_sec(1)); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); if (!rv) { rv = apr_file_read(readp, buf, &nbytes); ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv)); ABTS_INT_EQUAL(tc, 0, nbytes); } } static void read_write_notimeout(abts_case *tc, void *data) { apr_status_t rv; char *buf = "this is a test"; char *input; apr_size_t nbytes; nbytes = strlen("this is a test"); rv = apr_file_pipe_create(&readp, &writep, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_PTR_NOTNULL(tc, readp); ABTS_PTR_NOTNULL(tc, writep); rv = apr_file_write(writep, buf, &nbytes); ABTS_INT_EQUAL(tc, strlen("this is a test"), nbytes); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); nbytes = 256; input = apr_pcalloc(p, nbytes + 1); rv = apr_file_read(readp, input, &nbytes); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, strlen("this is a test"), nbytes); ABTS_STR_EQUAL(tc, "this is a test", input); } static void test_pipe_writefull(abts_case *tc, void *data) { int iterations = 1000; int i; int bytes_per_iteration = 8000; char *buf = (char *)malloc(bytes_per_iteration); char responsebuf[128]; apr_size_t nbytes; int bytes_processed; apr_proc_t proc = {0}; apr_procattr_t *procattr; const char *args[2]; apr_status_t rv; apr_exit_why_e why; rv = apr_procattr_create(&procattr, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_procattr_io_set(procattr, APR_CHILD_BLOCK, APR_CHILD_BLOCK, APR_CHILD_BLOCK); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_procattr_error_check_set(procattr, 1); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); args[0] = "readchild" EXTENSION; args[1] = NULL; rv = apr_proc_create(&proc, "./readchild" EXTENSION, args, NULL, procattr, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_file_pipe_timeout_set(proc.in, apr_time_from_sec(10)); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_file_pipe_timeout_set(proc.out, apr_time_from_sec(10)); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); i = iterations; do { rv = apr_file_write_full(proc.in, buf, bytes_per_iteration, NULL); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); } while (--i); free(buf); rv = apr_file_close(proc.in); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); nbytes = sizeof(responsebuf); rv = apr_file_read(proc.out, responsebuf, &nbytes); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); bytes_processed = (int)apr_strtoi64(responsebuf, NULL, 10); ABTS_INT_EQUAL(tc, iterations * bytes_per_iteration, bytes_processed); ABTS_ASSERT(tc, "wait for child process", apr_proc_wait(&proc, NULL, &why, APR_WAIT) == APR_CHILD_DONE); ABTS_ASSERT(tc, "child terminated normally", why == APR_PROC_EXIT); } abts_suite *testpipe(abts_suite *suite) { suite = ADD_SUITE(suite) abts_run_test(suite, create_pipe, NULL); abts_run_test(suite, close_pipe, NULL); abts_run_test(suite, set_timeout, NULL); abts_run_test(suite, close_pipe, NULL); abts_run_test(suite, read_write, NULL); abts_run_test(suite, close_pipe, NULL); abts_run_test(suite, read_write_notimeout, NULL); abts_run_test(suite, test_pipe_writefull, NULL); abts_run_test(suite, close_pipe, NULL); return suite; }
001-log4cxx
trunk/src/apr/test/testpipe.c
C
asf20
6,176
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "apr_pools.h" #include "abts.h" #ifndef APR_TEST_UTIL #define APR_TEST_UTIL /* XXX FIXME */ #ifdef WIN32 #define EXTENSION ".exe" #elif NETWARE #define EXTENSION ".nlm" #else #define EXTENSION #endif #define STRING_MAX 8096 /* Some simple functions to make the test apps easier to write and * a bit more consistent... */ extern apr_pool_t *p; /* Assert that RV is an APR_SUCCESS value; else fail giving strerror * for RV and CONTEXT message. */ void apr_assert_success(abts_case* tc, const char *context, apr_status_t rv, int lineno); #define APR_ASSERT_SUCCESS(tc, ctxt, rv) \ apr_assert_success(tc, ctxt, rv, __LINE__) void initialize(void); abts_suite *testatomic(abts_suite *suite); abts_suite *testdir(abts_suite *suite); abts_suite *testdso(abts_suite *suite); abts_suite *testdup(abts_suite *suite); abts_suite *testenv(abts_suite *suite); abts_suite *testfile(abts_suite *suite); abts_suite *testfilecopy(abts_suite *suite); abts_suite *testfileinfo(abts_suite *suite); abts_suite *testflock(abts_suite *suite); abts_suite *testfmt(abts_suite *suite); abts_suite *testfnmatch(abts_suite *suite); abts_suite *testgetopt(abts_suite *suite); abts_suite *testglobalmutex(abts_suite *suite); abts_suite *testhash(abts_suite *suite); abts_suite *testipsub(abts_suite *suite); abts_suite *testlock(abts_suite *suite); abts_suite *testlfs(abts_suite *suite); abts_suite *testmmap(abts_suite *suite); abts_suite *testnames(abts_suite *suite); abts_suite *testoc(abts_suite *suite); abts_suite *testpath(abts_suite *suite); abts_suite *testpipe(abts_suite *suite); abts_suite *testpoll(abts_suite *suite); abts_suite *testpool(abts_suite *suite); abts_suite *testproc(abts_suite *suite); abts_suite *testprocmutex(abts_suite *suite); abts_suite *testrand(abts_suite *suite); abts_suite *testrand2(abts_suite *suite); abts_suite *testsleep(abts_suite *suite); abts_suite *testshm(abts_suite *suite); abts_suite *testsock(abts_suite *suite); abts_suite *testsockets(abts_suite *suite); abts_suite *testsockopt(abts_suite *suite); abts_suite *teststr(abts_suite *suite); abts_suite *teststrnatcmp(abts_suite *suite); abts_suite *testtable(abts_suite *suite); abts_suite *testtemp(abts_suite *suite); abts_suite *testthread(abts_suite *suite); abts_suite *testtime(abts_suite *suite); abts_suite *testud(abts_suite *suite); abts_suite *testuser(abts_suite *suite); abts_suite *testvsn(abts_suite *suite); #endif /* APR_TEST_INCLUDES */
001-log4cxx
trunk/src/apr/test/testutil.h
C
asf20
3,289
/* Copyright 2000-2004 Ryan Bloom * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Portions of this file were taken from testall.c in the APR test suite, * written by members of the Apache Software Foundation. */ #include "abts.h" #include "abts_tests.h" #include "testutil.h" #define ABTS_STAT_SIZE 6 static char status[ABTS_STAT_SIZE] = {'|', '/', '-', '|', '\\', '-'}; static int curr_char; static int verbose = 0; static int exclude = 0; static int quiet = 0; static int list_tests = 0; const char **testlist = NULL; static int find_test_name(const char *testname) { int i; for (i = 0; testlist[i] != NULL; i++) { if (!strcmp(testlist[i], testname)) { return 1; } } return 0; } /* Determine if the test should be run at all */ static int should_test_run(const char *testname) { int found = 0; if (list_tests == 1) { return 0; } if (testlist == NULL) { return 1; } found = find_test_name(testname); if ((found && !exclude) || (!found && exclude)) { return 1; } return 0; } static void reset_status(void) { curr_char = 0; } static void update_status(void) { if (!quiet) { curr_char = (curr_char + 1) % ABTS_STAT_SIZE; fprintf(stdout, "\b%c", status[curr_char]); fflush(stdout); } } static void end_suite(abts_suite *suite) { if (suite != NULL) { sub_suite *last = suite->tail; if (!quiet) { fprintf(stdout, "\b"); fflush(stdout); } if (last->failed == 0) { fprintf(stdout, "SUCCESS\n"); fflush(stdout); } else { fprintf(stdout, "FAILED %d of %d\n", last->failed, last->num_test); fflush(stdout); } } } abts_suite *abts_add_suite(abts_suite *suite, const char *suite_name_full) { sub_suite *subsuite; char *p; const char *suite_name; curr_char = 0; /* Only end the suite if we actually ran it */ if (suite && suite->tail &&!suite->tail->not_run) { end_suite(suite); } subsuite = malloc(sizeof(*subsuite)); subsuite->num_test = 0; subsuite->failed = 0; subsuite->next = NULL; /* suite_name_full may be an absolute path depending on __FILE__ * expansion */ suite_name = strrchr(suite_name_full, '/'); if (suite_name) { suite_name++; } else { suite_name = suite_name_full; } p = strrchr(suite_name, '.'); if (p) { subsuite->name = memcpy(calloc(p - suite_name + 1, 1), suite_name, p - suite_name); } else { subsuite->name = suite_name; } if (list_tests) { fprintf(stdout, "%s\n", subsuite->name); } subsuite->not_run = 0; if (suite == NULL) { suite = malloc(sizeof(*suite)); suite->head = subsuite; suite->tail = subsuite; } else { suite->tail->next = subsuite; suite->tail = subsuite; } if (!should_test_run(subsuite->name)) { subsuite->not_run = 1; return suite; } reset_status(); fprintf(stdout, "%-20s: ", subsuite->name); update_status(); fflush(stdout); return suite; } void abts_run_test(abts_suite *ts, test_func f, void *value) { abts_case tc; sub_suite *ss; if (!should_test_run(ts->tail->name)) { return; } ss = ts->tail; tc.failed = 0; tc.suite = ss; ss->num_test++; update_status(); f(&tc, value); if (tc.failed) { ss->failed++; } } static int report(abts_suite *suite) { int count = 0; sub_suite *dptr; if (suite && suite->tail &&!suite->tail->not_run) { end_suite(suite); } for (dptr = suite->head; dptr; dptr = dptr->next) { count += dptr->failed; } if (list_tests) { return 0; } if (count == 0) { printf("All tests passed.\n"); return 0; } dptr = suite->head; fprintf(stdout, "%-15s\t\tTotal\tFail\tFailed %%\n", "Failed Tests"); fprintf(stdout, "===================================================\n"); while (dptr != NULL) { if (dptr->failed != 0) { float percent = ((float)dptr->failed / (float)dptr->num_test); fprintf(stdout, "%-15s\t\t%5d\t%4d\t%6.2f%%\n", dptr->name, dptr->num_test, dptr->failed, percent * 100); } dptr = dptr->next; } return 1; } void abts_log_message(const char *fmt, ...) { va_list args; update_status(); if (verbose) { va_start(args, fmt); vfprintf(stderr, fmt, args); va_end(args); fprintf(stderr, "\n"); fflush(stderr); } } void abts_int_equal(abts_case *tc, const int expected, const int actual, int lineno) { update_status(); if (tc->failed) return; if (expected == actual) return; tc->failed = TRUE; if (verbose) { fprintf(stderr, "Line %d: expected <%d>, but saw <%d>\n", lineno, expected, actual); fflush(stderr); } } void abts_int_nequal(abts_case *tc, const int expected, const int actual, int lineno) { update_status(); if (tc->failed) return; if (expected != actual) return; tc->failed = TRUE; if (verbose) { fprintf(stderr, "Line %d: expected <%d>, but saw <%d>\n", lineno, expected, actual); fflush(stderr); } } void abts_str_equal(abts_case *tc, const char *expected, const char *actual, int lineno) { update_status(); if (tc->failed) return; if (!expected && !actual) return; if (expected && actual) if (!strcmp(expected, actual)) return; tc->failed = TRUE; if (verbose) { fprintf(stderr, "Line %d: expected <%s>, but saw <%s>\n", lineno, expected, actual); fflush(stderr); } } void abts_str_nequal(abts_case *tc, const char *expected, const char *actual, size_t n, int lineno) { update_status(); if (tc->failed) return; if (!strncmp(expected, actual, n)) return; tc->failed = TRUE; if (verbose) { fprintf(stderr, "Line %d: expected <%s>, but saw <%s>\n", lineno, expected, actual); fflush(stderr); } } void abts_ptr_notnull(abts_case *tc, const void *ptr, int lineno) { update_status(); if (tc->failed) return; if (ptr != NULL) return; tc->failed = TRUE; if (verbose) { fprintf(stderr, "Line %d: Expected NULL, but saw <%p>\n", lineno, ptr); fflush(stderr); } } void abts_ptr_equal(abts_case *tc, const void *expected, const void *actual, int lineno) { update_status(); if (tc->failed) return; if (expected == actual) return; tc->failed = TRUE; if (verbose) { fprintf(stderr, "Line %d: expected <%p>, but saw <%p>\n", lineno, expected, actual); fflush(stderr); } } void abts_fail(abts_case *tc, const char *message, int lineno) { update_status(); if (tc->failed) return; tc->failed = TRUE; if (verbose) { fprintf(stderr, "Line %d: %s\n", lineno, message); fflush(stderr); } } void abts_assert(abts_case *tc, const char *message, int condition, int lineno) { update_status(); if (tc->failed) return; if (condition) return; tc->failed = TRUE; if (verbose) { fprintf(stderr, "Line %d: %s\n", lineno, message); fflush(stderr); } } void abts_true(abts_case *tc, int condition, int lineno) { update_status(); if (tc->failed) return; if (condition) return; tc->failed = TRUE; if (verbose) { fprintf(stderr, "Line %d: Condition is false, but expected true\n", lineno); fflush(stderr); } } void abts_not_impl(abts_case *tc, const char *message, int lineno) { update_status(); tc->suite->not_impl++; if (verbose) { fprintf(stderr, "Line %d: %s\n", lineno, message); fflush(stderr); } } int main(int argc, const char *const argv[]) { int i; int rv; int list_provided = 0; abts_suite *suite = NULL; initialize(); for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-v")) { verbose = 1; continue; } if (!strcmp(argv[i], "-x")) { exclude = 1; continue; } if (!strcmp(argv[i], "-l")) { list_tests = 1; continue; } if (!strcmp(argv[i], "-q")) { quiet = 1; continue; } if (argv[i][0] == '-') { fprintf(stderr, "Invalid option: `%s'\n", argv[i]); exit(1); } list_provided = 1; } if (list_provided) { /* Waste a little space here, because it is easier than counting the * number of tests listed. Besides it is at most three char *. */ testlist = calloc(argc + 1, sizeof(char *)); for (i = 1; i < argc; i++) { testlist[i - 1] = argv[i]; } } for (i = 0; i < (sizeof(alltests) / sizeof(struct testlist *)); i++) { suite = alltests[i].func(suite); } rv = report(suite); return rv; }
001-log4cxx
trunk/src/apr/test/abts.c
C
asf20
9,735
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <stdio.h> #include <stdlib.h> #include "apr_file_io.h" #include "apr_errno.h" #include "apr_general.h" #include "apr_lib.h" #include "apr_strings.h" #include "testutil.h" static apr_pool_t *pool; static char *testdata; static int cleanup_called = 0; static apr_status_t string_cleanup(void *data) { cleanup_called = 1; return APR_SUCCESS; } static void set_userdata(abts_case *tc, void *data) { apr_status_t rv; rv = apr_pool_userdata_set(testdata, "TEST", string_cleanup, pool); ABTS_INT_EQUAL(tc, rv, APR_SUCCESS); } static void get_userdata(abts_case *tc, void *data) { apr_status_t rv; void *retdata; rv = apr_pool_userdata_get(&retdata, "TEST", pool); ABTS_INT_EQUAL(tc, rv, APR_SUCCESS); ABTS_STR_EQUAL(tc, retdata, testdata); } static void get_nonexistkey(abts_case *tc, void *data) { apr_status_t rv; void *retdata; rv = apr_pool_userdata_get(&retdata, "DOESNTEXIST", pool); ABTS_INT_EQUAL(tc, rv, APR_SUCCESS); ABTS_PTR_EQUAL(tc, retdata, NULL); } static void post_pool_clear(abts_case *tc, void *data) { apr_status_t rv; void *retdata; rv = apr_pool_userdata_get(&retdata, "DOESNTEXIST", pool); ABTS_INT_EQUAL(tc, rv, APR_SUCCESS); ABTS_PTR_EQUAL(tc, retdata, NULL); } abts_suite *testud(abts_suite *suite) { suite = ADD_SUITE(suite) apr_pool_create(&pool, p); testdata = apr_pstrdup(pool, "This is a test\n"); abts_run_test(suite, set_userdata, NULL); abts_run_test(suite, get_userdata, NULL); abts_run_test(suite, get_nonexistkey, NULL); apr_pool_clear(pool); abts_run_test(suite, post_pool_clear, NULL); return suite; }
001-log4cxx
trunk/src/apr/test/testud.c
C
asf20
2,475
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "testflock.h" #include "testutil.h" #include "apr_pools.h" #include "apr_thread_proc.h" #include "apr_file_io.h" #include "apr_file_info.h" #include "apr_general.h" #include "apr_strings.h" static int launch_reader(abts_case *tc) { apr_proc_t proc = {0}; apr_procattr_t *procattr; const char *args[2]; apr_status_t rv; apr_exit_why_e why; int exitcode; rv = apr_procattr_create(&procattr, p); APR_ASSERT_SUCCESS(tc, "Couldn't create procattr", rv); rv = apr_procattr_io_set(procattr, APR_NO_PIPE, APR_NO_PIPE, APR_NO_PIPE); APR_ASSERT_SUCCESS(tc, "Couldn't set io in procattr", rv); rv = apr_procattr_error_check_set(procattr, 1); APR_ASSERT_SUCCESS(tc, "Couldn't set error check in procattr", rv); args[0] = "tryread" EXTENSION; args[1] = NULL; rv = apr_proc_create(&proc, "./tryread" EXTENSION, args, NULL, procattr, p); APR_ASSERT_SUCCESS(tc, "Couldn't launch program", rv); ABTS_ASSERT(tc, "wait for child process", apr_proc_wait(&proc, &exitcode, &why, APR_WAIT) == APR_CHILD_DONE); ABTS_ASSERT(tc, "child terminated normally", why == APR_PROC_EXIT); return exitcode; } static void test_withlock(abts_case *tc, void *data) { apr_file_t *file; apr_status_t rv; int code; rv = apr_file_open(&file, TESTFILE, APR_WRITE|APR_CREATE, APR_OS_DEFAULT, p); APR_ASSERT_SUCCESS(tc, "Could not create file.", rv); ABTS_PTR_NOTNULL(tc, file); rv = apr_file_lock(file, APR_FLOCK_EXCLUSIVE); APR_ASSERT_SUCCESS(tc, "Could not lock the file.", rv); ABTS_PTR_NOTNULL(tc, file); code = launch_reader(tc); ABTS_INT_EQUAL(tc, FAILED_READ, code); (void) apr_file_close(file); } static void test_withoutlock(abts_case *tc, void *data) { int code; code = launch_reader(tc); ABTS_INT_EQUAL(tc, SUCCESSFUL_READ, code); } static void remove_lockfile(abts_case *tc, void *data) { APR_ASSERT_SUCCESS(tc, "Couldn't remove lock file.", apr_file_remove(TESTFILE, p)); } abts_suite *testflock(abts_suite *suite) { suite = ADD_SUITE(suite) abts_run_test(suite, test_withlock, NULL); abts_run_test(suite, test_withoutlock, NULL); abts_run_test(suite, remove_lockfile, NULL); return suite; }
001-log4cxx
trunk/src/apr/test/testflock.c
C
asf20
3,132
srcdir = @srcdir@ VPATH = @srcdir@ # PROGRAMS includes all test programs built on this platform. # STDTEST_PORTABLE # test programs invoked via standard user interface, run on all platforms # STDTEST_NONPORTABLE # test programs invoked via standard user interface, not portable # OTHER_PROGRAMS # programs such as sendfile, that have to be invoked in a special sequence # or with special parameters STDTEST_PORTABLE = \ testlockperf@EXEEXT@ \ testshmproducer@EXEEXT@ \ testshmconsumer@EXEEXT@ \ testmutexscope@EXEEXT@ \ testall@EXEEXT@ OTHER_PROGRAMS = sendfile@EXEEXT@ PROGRAMS = $(STDTEST_PORTABLE) $(STDTEST_NONPORTABLE) $(OTHER_PROGRAMS) TARGETS = $(PROGRAMS) # bring in rules.mk for standard functionality @INCLUDE_RULES@ LOCAL_LIBS=../lib@APR_LIBNAME@.la CLEAN_TARGETS = testfile.tmp mod_test.slo proc_child@EXEEXT@ occhild@EXEEXT@ \ readchild@EXEEXT@ tryread@EXEEXT@ sockchild@EXEEXT@ \ globalmutexchild@EXEEXT@ lfstests/large.bin \ data/test*.txt data/test*.dat CLEAN_SUBDIRS = internal INCDIR=../include INCLUDES=-I$(INCDIR) -I$(srcdir)/../include # link programs using -no-install to get real executables not # libtool wrapper scripts which link an executable when first run. LINK_PROG = $(LIBTOOL) $(LTFLAGS) --mode=link $(LT_LDFLAGS) $(COMPILE) @LT_NO_INSTALL@ $(ALL_LDFLAGS) -o $@ check: $(STDTEST_PORTABLE) $(STDTEST_NONPORTABLE) for prog in $(STDTEST_PORTABLE) $(STDTEST_NONPORTABLE); do \ ./$$prog; \ if test $$? = 255; then \ echo "$$prog failed"; \ break; \ fi; \ done occhild@EXEEXT@: occhild.lo $(LOCAL_LIBS) $(LINK_PROG) occhild.lo $(LOCAL_LIBS) $(ALL_LIBS) sockchild@EXEEXT@: sockchild.lo $(LOCAL_LIBS) $(LINK_PROG) sockchild.lo $(LOCAL_LIBS) $(ALL_LIBS) readchild@EXEEXT@: readchild.lo $(LOCAL_LIBS) $(LINK_PROG) readchild.lo $(LOCAL_LIBS) $(ALL_LIBS) globalmutexchild@EXEEXT@: globalmutexchild.lo $(LOCAL_LIBS) $(LINK_PROG) globalmutexchild.lo $(LOCAL_LIBS) $(ALL_LIBS) tryread@EXEEXT@: tryread.lo $(LOCAL_LIBS) $(LINK_PROG) tryread.lo $(LOCAL_LIBS) $(ALL_LIBS) proc_child@EXEEXT@: proc_child.lo $(LOCAL_LIBS) $(LINK_PROG) proc_child.lo $(LOCAL_LIBS) $(ALL_LIBS) # FIXME: -prefer-pic is only supported with libtool-1.4+ mod_test.slo: $(srcdir)/mod_test.c $(LIBTOOL) $(LTFLAGS) --mode=compile $(COMPILE) -prefer-pic -c $(srcdir)/mod_test.c && touch $@ mod_test.la: mod_test.slo $(LOCAL_LIBS) $(LIBTOOL) $(LTFLAGS) --mode=link $(COMPILE) -rpath `pwd` -avoid-version -module mod_test.lo $(LT_LDFLAGS) $(ALL_LDFLAGS) -o $@ libmod_test.la: mod_test.slo $(LOCAL_LIBS) $(LIBTOOL) $(LTFLAGS) --mode=link $(COMPILE) -rpath `pwd` -avoid-version mod_test.lo $(LT_LDFLAGS) $(ALL_LDFLAGS) -o $@ $(LOCAL_LIBS) $(ALL_LIBS) testlockperf@EXEEXT@: testlockperf.lo $(LOCAL_LIBS) $(LINK_PROG) testlockperf.lo $(LOCAL_LIBS) $(ALL_LIBS) sendfile@EXEEXT@: sendfile.lo $(LOCAL_LIBS) $(LINK_PROG) sendfile.lo $(LOCAL_LIBS) $(ALL_LIBS) testshmproducer@EXEEXT@: testshmproducer.lo $(LOCAL_LIBS) $(LINK_PROG) testshmproducer.lo $(LOCAL_LIBS) $(ALL_LIBS) testshmconsumer@EXEEXT@: testshmconsumer.lo $(LOCAL_LIBS) $(LINK_PROG) testshmconsumer.lo $(LOCAL_LIBS) $(ALL_LIBS) testprocmutex@EXEEXT@: testprocmutex.lo $(LOCAL_LIBS) $(LINK_PROG) testprocmutex.lo $(LOCAL_LIBS) $(ALL_LIBS) testmutexscope@EXEEXT@: testmutexscope.lo $(LOCAL_LIBS) $(LINK_PROG) testmutexscope.lo $(LOCAL_LIBS) $(ALL_LIBS) TESTS = testutil.lo testtime.lo teststr.lo testvsn.lo testipsub.lo \ testmmap.lo testud.lo testtable.lo testsleep.lo testpools.lo \ testfmt.lo testfile.lo testdir.lo testfileinfo.lo testrand.lo \ testdso.lo testoc.lo testdup.lo testsockets.lo testproc.lo \ testpoll.lo testlock.lo testsockopt.lo testpipe.lo testthread.lo \ testhash.lo testargs.lo testnames.lo testuser.lo testpath.lo \ testenv.lo testprocmutex.lo testrand2.lo testfnmatch.lo \ testatomic.lo testflock.lo testshm.lo testsock.lo testglobalmutex.lo \ teststrnatcmp.lo testfilecopy.lo testtemp.lo testlfs.lo testall@EXEEXT@: $(TESTS) mod_test.la libmod_test.la occhild@EXEEXT@ \ readchild@EXEEXT@ abts.lo proc_child@EXEEXT@ \ tryread@EXEEXT@ sockchild@EXEEXT@ globalmutexchild@EXEEXT@ \ $(LOCAL_LIBS) $(LINK_PROG) $(TESTS) abts.lo $(LOCAL_LIBS) $(ALL_LIBS) # DO NOT REMOVE
001-log4cxx
trunk/src/apr/test/Makefile.in
Makefile
asf20
4,245
#include <netware.h> #include <screen.h> #include "testutil.h" void _NonAppStop( void ) { pressanykey(); } /* static void test_not_impl(CuTest *tc) { CuNotImpl(tc, "Test not implemented on this platform yet"); } */
001-log4cxx
trunk/src/apr/test/nw_misc.c
C
asf20
226
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "testglobalmutex.h" #include "apr_thread_proc.h" #include "apr_global_mutex.h" #include "apr_strings.h" #include "apr_errno.h" #include "testutil.h" static void launch_child(abts_case *tc, apr_lockmech_e mech, apr_proc_t *proc, apr_pool_t *p) { apr_procattr_t *procattr; const char *args[3]; apr_status_t rv; rv = apr_procattr_create(&procattr, p); APR_ASSERT_SUCCESS(tc, "Couldn't create procattr", rv); rv = apr_procattr_io_set(procattr, APR_NO_PIPE, APR_NO_PIPE, APR_NO_PIPE); APR_ASSERT_SUCCESS(tc, "Couldn't set io in procattr", rv); rv = apr_procattr_error_check_set(procattr, 1); APR_ASSERT_SUCCESS(tc, "Couldn't set error check in procattr", rv); args[0] = "globalmutexchild" EXTENSION; args[1] = (const char*)apr_itoa(p, (int)mech); args[2] = NULL; rv = apr_proc_create(proc, "./globalmutexchild" EXTENSION, args, NULL, procattr, p); APR_ASSERT_SUCCESS(tc, "Couldn't launch program", rv); } static int wait_child(abts_case *tc, apr_proc_t *proc) { int exitcode; apr_exit_why_e why; ABTS_ASSERT(tc, "Error waiting for child process", apr_proc_wait(proc, &exitcode, &why, APR_WAIT) == APR_CHILD_DONE); ABTS_ASSERT(tc, "child didn't terminate normally", why == APR_PROC_EXIT); return exitcode; } /* return symbolic name for a locking meechanism */ static const char *mutexname(apr_lockmech_e mech) { switch (mech) { case APR_LOCK_FCNTL: return "fcntl"; case APR_LOCK_FLOCK: return "flock"; case APR_LOCK_SYSVSEM: return "sysvsem"; case APR_LOCK_PROC_PTHREAD: return "proc_pthread"; case APR_LOCK_POSIXSEM: return "posixsem"; case APR_LOCK_DEFAULT: return "default"; default: return "unknown"; } } static void test_exclusive(abts_case *tc, void *data) { apr_lockmech_e mech = *(apr_lockmech_e *)data; apr_proc_t p1, p2, p3, p4; apr_status_t rv; apr_global_mutex_t *global_lock; int x = 0; abts_log_message("lock mechanism is: "); abts_log_message(mutexname(mech)); rv = apr_global_mutex_create(&global_lock, LOCKNAME, mech, p); APR_ASSERT_SUCCESS(tc, "Error creating mutex", rv); launch_child(tc, mech, &p1, p); launch_child(tc, mech, &p2, p); launch_child(tc, mech, &p3, p); launch_child(tc, mech, &p4, p); x += wait_child(tc, &p1); x += wait_child(tc, &p2); x += wait_child(tc, &p3); x += wait_child(tc, &p4); if (x != MAX_COUNTER) { char buf[200]; sprintf(buf, "global mutex '%s' failed: %d not %d", mutexname(mech), x, MAX_COUNTER); abts_fail(tc, buf, __LINE__); } } abts_suite *testglobalmutex(abts_suite *suite) { apr_lockmech_e mech = APR_LOCK_DEFAULT; suite = ADD_SUITE(suite) abts_run_test(suite, test_exclusive, &mech); #if APR_HAS_POSIXSEM_SERIALIZE mech = APR_LOCK_POSIXSEM; abts_run_test(suite, test_exclusive, &mech); #endif #if APR_HAS_SYSVSEM_SERIALIZE mech = APR_LOCK_SYSVSEM; abts_run_test(suite, test_exclusive, &mech); #endif #if APR_HAS_PROC_PTHREAD_SERIALIZE mech = APR_LOCK_PROC_PTHREAD; abts_run_test(suite, test_exclusive, &mech); #endif #if APR_HAS_FCNTL_SERIALIZE mech = APR_LOCK_FCNTL; abts_run_test(suite, test_exclusive, &mech); #endif #if APR_HAS_FLOCK_SERIALIZE mech = APR_LOCK_FLOCK; abts_run_test(suite, test_exclusive, &mech); #endif return suite; }
001-log4cxx
trunk/src/apr/test/testglobalmutex.c
C
asf20
4,264
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "time.h" #include "apr_thread_proc.h" #include "apr_errno.h" #include "apr_general.h" #include "apr_lib.h" #include <errno.h> #include <stdio.h> #include <stdlib.h> #include "testutil.h" #define SLEEP_INTERVAL 5 static void sleep_one(abts_case *tc, void *data) { time_t pretime = time(NULL); time_t posttime; time_t timediff; apr_sleep(apr_time_from_sec(SLEEP_INTERVAL)); posttime = time(NULL); /* normalize the timediff. We should have slept for SLEEP_INTERVAL, so * we should just subtract that out. */ timediff = posttime - pretime - SLEEP_INTERVAL; ABTS_TRUE(tc, timediff >= 0); ABTS_TRUE(tc, timediff <= 1); } abts_suite *testsleep(abts_suite *suite) { suite = ADD_SUITE(suite) abts_run_test(suite, sleep_one, NULL); return suite; }
001-log4cxx
trunk/src/apr/test/testsleep.c
C
asf20
1,614
#include "apr.h" #include <stdio.h> #if APR_HAVE_UNISTD_H #include <unistd.h> #endif #if APR_HAVE_IO_H #include <io.h> #endif #include <stdlib.h> int main(void) { char buf[256]; apr_ssize_t bytes; bytes = read(STDIN_FILENO, buf, 256); if (bytes > 0) write(STDOUT_FILENO, buf, bytes); return 0; /* just to keep the compiler happy */ }
001-log4cxx
trunk/src/apr/test/proc_child.c
C
asf20
369
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "apr_file_io.h" #include "apr_errno.h" #include "apr_strings.h" #include "testutil.h" static void less0(abts_case *tc, void *data) { int rv = apr_strnatcmp("a", "b"); ABTS_ASSERT(tc, "didn't compare simple strings properly", rv < 0); } static void str_equal(abts_case *tc, void *data) { int rv = apr_strnatcmp("a", "a"); ABTS_ASSERT(tc, "didn't compare simple strings properly", rv == 0); } static void more0(abts_case *tc, void *data) { int rv = apr_strnatcmp("b", "a"); ABTS_ASSERT(tc, "didn't compare simple strings properly", rv > 0); } static void less_ignore_case(abts_case *tc, void *data) { int rv = apr_strnatcasecmp("a", "B"); ABTS_ASSERT(tc, "didn't compare simple strings properly", rv < 0); } static void str_equal_ignore_case(abts_case *tc, void *data) { int rv = apr_strnatcasecmp("a", "A"); ABTS_ASSERT(tc, "didn't compare simple strings properly", rv == 0); } static void more_ignore_case(abts_case *tc, void *data) { int rv = apr_strnatcasecmp("b", "A"); ABTS_ASSERT(tc, "didn't compare simple strings properly", rv > 0); } static void natcmp(abts_case *tc, void *data) { int rv = apr_strnatcasecmp("a2", "a10"); ABTS_ASSERT(tc, "didn't compare simple strings properly", rv < 0); } abts_suite *teststrnatcmp(abts_suite *suite) { suite = ADD_SUITE(suite) abts_run_test(suite, less0, NULL); abts_run_test(suite, str_equal, NULL); abts_run_test(suite, more0, NULL); abts_run_test(suite, less_ignore_case, NULL); abts_run_test(suite, str_equal_ignore_case, NULL); abts_run_test(suite, more_ignore_case, NULL); abts_run_test(suite, natcmp, NULL); return suite; }
001-log4cxx
trunk/src/apr/test/teststrnatcmp.c
C
asf20
2,488
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "apr_file_io.h" #include "apr_file_info.h" #include "apr_errno.h" #include "apr_general.h" #include "apr_poll.h" #include "apr_strings.h" #include "apr_lib.h" #include "apr_mmap.h" #include "testutil.h" /* Only enable these tests by default on platforms which support sparse * files... just Unixes? */ #if defined(WIN32) || defined(OS2) || defined(NETWARE) static void test_nolfs(abts_case *tc, void *data) { ABTS_NOT_IMPL(tc, "Large Files tests require Sparse file support"); } #elif APR_HAS_LARGE_FILES #define USE_LFS_TESTS /* Tests which create an 8Gb sparse file and then check it can be used * as normal. */ static apr_off_t eightGb = APR_INT64_C(2) << 32; static int madefile = 0; #define PRECOND if (!madefile) { ABTS_NOT_IMPL(tc, "Large file tests not enabled"); return; } #define TESTDIR "lfstests" #define TESTFILE "large.bin" #define TESTFN "lfstests/large.bin" static void test_open(abts_case *tc, void *data) { apr_file_t *f; apr_status_t rv; rv = apr_dir_make(TESTDIR, APR_OS_DEFAULT, p); if (rv && !APR_STATUS_IS_EEXIST(rv)) { APR_ASSERT_SUCCESS(tc, "make test directory", rv); } APR_ASSERT_SUCCESS(tc, "open file", apr_file_open(&f, TESTFN, APR_CREATE | APR_WRITE | APR_TRUNCATE, APR_OS_DEFAULT, p)); rv = apr_file_trunc(f, eightGb); APR_ASSERT_SUCCESS(tc, "close large file", apr_file_close(f)); /* 8Gb may pass rlimits or filesystem limits */ if (APR_STATUS_IS_EINVAL(rv) #ifdef EFBIG || rv == EFBIG #endif ) { ABTS_NOT_IMPL(tc, "Creation of large file (limited by rlimit or fs?)"); } else { APR_ASSERT_SUCCESS(tc, "truncate file to 8gb", rv); } madefile = rv == APR_SUCCESS; } static void test_reopen(abts_case *tc, void *data) { apr_file_t *fh; apr_finfo_t finfo; PRECOND; APR_ASSERT_SUCCESS(tc, "re-open 8Gb file", apr_file_open(&fh, TESTFN, APR_READ, APR_OS_DEFAULT, p)); APR_ASSERT_SUCCESS(tc, "file_info_get failed", apr_file_info_get(&finfo, APR_FINFO_NORM, fh)); ABTS_ASSERT(tc, "file_info_get gave incorrect size", finfo.size == eightGb); APR_ASSERT_SUCCESS(tc, "re-close large file", apr_file_close(fh)); } static void test_stat(abts_case *tc, void *data) { apr_finfo_t finfo; PRECOND; APR_ASSERT_SUCCESS(tc, "stat large file", apr_stat(&finfo, TESTFN, APR_FINFO_NORM, p)); ABTS_ASSERT(tc, "stat gave incorrect size", finfo.size == eightGb); } static void test_readdir(abts_case *tc, void *data) { apr_dir_t *dh; apr_status_t rv; PRECOND; APR_ASSERT_SUCCESS(tc, "open test directory", apr_dir_open(&dh, TESTDIR, p)); do { apr_finfo_t finfo; rv = apr_dir_read(&finfo, APR_FINFO_NORM, dh); if (rv == APR_SUCCESS && strcmp(finfo.name, TESTFILE) == 0) { ABTS_ASSERT(tc, "apr_dir_read gave incorrect size for large file", finfo.size == eightGb); } } while (rv == APR_SUCCESS); if (!APR_STATUS_IS_ENOENT(rv)) { APR_ASSERT_SUCCESS(tc, "apr_dir_read failed", rv); } APR_ASSERT_SUCCESS(tc, "close test directory", apr_dir_close(dh)); } #define TESTSTR "Hello, world." static void test_append(abts_case *tc, void *data) { apr_file_t *fh; apr_finfo_t finfo; PRECOND; APR_ASSERT_SUCCESS(tc, "open 8Gb file for append", apr_file_open(&fh, TESTFN, APR_WRITE | APR_APPEND, APR_OS_DEFAULT, p)); APR_ASSERT_SUCCESS(tc, "append to 8Gb file", apr_file_write_full(fh, TESTSTR, strlen(TESTSTR), NULL)); APR_ASSERT_SUCCESS(tc, "file_info_get failed", apr_file_info_get(&finfo, APR_FINFO_NORM, fh)); ABTS_ASSERT(tc, "file_info_get gave incorrect size", finfo.size == eightGb + strlen(TESTSTR)); APR_ASSERT_SUCCESS(tc, "close 8Gb file", apr_file_close(fh)); } static void test_seek(abts_case *tc, void *data) { apr_file_t *fh; apr_off_t pos; PRECOND; APR_ASSERT_SUCCESS(tc, "open 8Gb file for writing", apr_file_open(&fh, TESTFN, APR_WRITE, APR_OS_DEFAULT, p)); pos = 0; APR_ASSERT_SUCCESS(tc, "relative seek to end", apr_file_seek(fh, APR_END, &pos)); ABTS_ASSERT(tc, "seek to END gave 8Gb", pos == eightGb); pos = eightGb; APR_ASSERT_SUCCESS(tc, "seek to 8Gb", apr_file_seek(fh, APR_SET, &pos)); ABTS_ASSERT(tc, "seek gave 8Gb offset", pos == eightGb); pos = 0; APR_ASSERT_SUCCESS(tc, "relative seek to 0", apr_file_seek(fh, APR_CUR, &pos)); ABTS_ASSERT(tc, "relative seek gave 8Gb offset", pos == eightGb); apr_file_close(fh); } static void test_write(abts_case *tc, void *data) { apr_file_t *fh; apr_off_t pos = eightGb - 4; PRECOND; APR_ASSERT_SUCCESS(tc, "re-open 8Gb file", apr_file_open(&fh, TESTFN, APR_WRITE, APR_OS_DEFAULT, p)); APR_ASSERT_SUCCESS(tc, "seek to 8Gb - 4", apr_file_seek(fh, APR_SET, &pos)); ABTS_ASSERT(tc, "seek gave 8Gb-4 offset", pos == eightGb - 4); APR_ASSERT_SUCCESS(tc, "write magic string to 8Gb-4", apr_file_write_full(fh, "FISH", 4, NULL)); APR_ASSERT_SUCCESS(tc, "close 8Gb file", apr_file_close(fh)); } #if APR_HAS_MMAP static void test_mmap(abts_case *tc, void *data) { apr_mmap_t *map; apr_file_t *fh; apr_size_t len = 16384; /* hopefully a multiple of the page size */ apr_off_t off = eightGb - len; void *ptr; PRECOND; APR_ASSERT_SUCCESS(tc, "open 8gb file for mmap", apr_file_open(&fh, TESTFN, APR_READ, APR_OS_DEFAULT, p)); APR_ASSERT_SUCCESS(tc, "mmap 8Gb file", apr_mmap_create(&map, fh, off, len, APR_MMAP_READ, p)); APR_ASSERT_SUCCESS(tc, "close file", apr_file_close(fh)); ABTS_ASSERT(tc, "mapped a 16K block", map->size == len); APR_ASSERT_SUCCESS(tc, "get pointer into mmaped region", apr_mmap_offset(&ptr, map, len - 4)); ABTS_ASSERT(tc, "pointer was not NULL", ptr != NULL); ABTS_ASSERT(tc, "found the magic string", memcmp(ptr, "FISH", 4) == 0); APR_ASSERT_SUCCESS(tc, "delete mmap handle", apr_mmap_delete(map)); } #endif /* APR_HAS_MMAP */ static void test_format(abts_case *tc, void *data) { apr_off_t off; PRECOND; off = apr_atoi64(apr_off_t_toa(p, eightGb)); ABTS_ASSERT(tc, "apr_atoi64 parsed apr_off_t_toa result incorrectly", off == eightGb); } #else static void test_nolfs(abts_case *tc, void *data) { ABTS_NOT_IMPL(tc, "Large Files not supported"); } #endif abts_suite *testlfs(abts_suite *suite) { suite = ADD_SUITE(suite) #ifdef USE_LFS_TESTS abts_run_test(suite, test_open, NULL); abts_run_test(suite, test_reopen, NULL); abts_run_test(suite, test_stat, NULL); abts_run_test(suite, test_readdir, NULL); abts_run_test(suite, test_seek, NULL); abts_run_test(suite, test_append, NULL); abts_run_test(suite, test_write, NULL); #if APR_HAS_MMAP abts_run_test(suite, test_mmap, NULL); #endif abts_run_test(suite, test_format, NULL); #else abts_run_test(suite, test_nolfs, NULL); #endif return suite; }
001-log4cxx
trunk/src/apr/test/testlfs.c
C
asf20
8,401
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifdef WIN32 /* POSIX defines 1024 for the FD_SETSIZE */ #define FD_SETSIZE 1024 #endif #include "apr.h" #include "apr_poll.h" #include "apr_time.h" #include "apr_portable.h" #include "apr_arch_networkio.h" #include "apr_arch_file_io.h" #include "apr_arch_poll_private.h" #ifdef POLL_USES_SELECT APR_DECLARE(apr_status_t) apr_poll(apr_pollfd_t *aprset, int num, apr_int32_t *nsds, apr_interval_time_t timeout) { fd_set readset, writeset, exceptset; int rv, i; int maxfd = -1; struct timeval tv, *tvptr; #ifdef NETWARE apr_datatype_e set_type = APR_NO_DESC; #endif if (timeout < 0) { tvptr = NULL; } else { tv.tv_sec = (long) apr_time_sec(timeout); tv.tv_usec = (long) apr_time_usec(timeout); tvptr = &tv; } FD_ZERO(&readset); FD_ZERO(&writeset); FD_ZERO(&exceptset); for (i = 0; i < num; i++) { apr_os_sock_t fd; aprset[i].rtnevents = 0; if (aprset[i].desc_type == APR_POLL_SOCKET) { #ifdef NETWARE if (HAS_PIPES(set_type)) { return APR_EBADF; } else { set_type = APR_POLL_SOCKET; } #endif fd = aprset[i].desc.s->socketdes; } else if (aprset[i].desc_type == APR_POLL_FILE) { #if !APR_FILES_AS_SOCKETS return APR_EBADF; #else #ifdef NETWARE if (aprset[i].desc.f->is_pipe && !HAS_SOCKETS(set_type)) { set_type = APR_POLL_FILE; } else return APR_EBADF; #endif /* NETWARE */ fd = aprset[i].desc.f->filedes; #endif /* APR_FILES_AS_SOCKETS */ } else { break; } #if !defined(WIN32) && !defined(NETWARE) /* socket sets handled with array of handles */ if (fd >= FD_SETSIZE) { /* XXX invent new error code so application has a clue */ return APR_EBADF; } #endif if (aprset[i].reqevents & APR_POLLIN) { FD_SET(fd, &readset); } if (aprset[i].reqevents & APR_POLLOUT) { FD_SET(fd, &writeset); } if (aprset[i].reqevents & (APR_POLLPRI | APR_POLLERR | APR_POLLHUP | APR_POLLNVAL)) { FD_SET(fd, &exceptset); } if ((int) fd > maxfd) { maxfd = (int) fd; } } #ifdef NETWARE if (HAS_PIPES(set_type)) { rv = pipe_select(maxfd + 1, &readset, &writeset, &exceptset, tvptr); } else { #endif rv = select(maxfd + 1, &readset, &writeset, &exceptset, tvptr); #ifdef NETWARE } #endif (*nsds) = rv; if ((*nsds) == 0) { return APR_TIMEUP; } if ((*nsds) < 0) { return apr_get_netos_error(); } (*nsds) = 0; for (i = 0; i < num; i++) { apr_os_sock_t fd; if (aprset[i].desc_type == APR_POLL_SOCKET) { fd = aprset[i].desc.s->socketdes; } else if (aprset[i].desc_type == APR_POLL_FILE) { #if !APR_FILES_AS_SOCKETS return APR_EBADF; #else fd = aprset[i].desc.f->filedes; #endif } else { break; } if (FD_ISSET(fd, &readset)) { aprset[i].rtnevents |= APR_POLLIN; } if (FD_ISSET(fd, &writeset)) { aprset[i].rtnevents |= APR_POLLOUT; } if (FD_ISSET(fd, &exceptset)) { aprset[i].rtnevents |= APR_POLLERR; } if (aprset[i].rtnevents) { (*nsds)++; } } return APR_SUCCESS; } #endif /* POLL_USES_SELECT */ #ifdef POLLSET_USES_SELECT struct apr_pollset_t { apr_pool_t *pool; apr_uint32_t nelts; apr_uint32_t nalloc; fd_set readset, writeset, exceptset; int maxfd; apr_pollfd_t *query_set; apr_pollfd_t *result_set; #ifdef NETWARE int set_type; #endif }; APR_DECLARE(apr_status_t) apr_pollset_create(apr_pollset_t **pollset, apr_uint32_t size, apr_pool_t *p, apr_uint32_t flags) { if (flags & APR_POLLSET_THREADSAFE) { *pollset = NULL; return APR_ENOTIMPL; } #ifdef FD_SETSIZE if (size > FD_SETSIZE) { *pollset = NULL; return APR_EINVAL; } #endif *pollset = apr_palloc(p, sizeof(**pollset)); (*pollset)->nelts = 0; (*pollset)->nalloc = size; (*pollset)->pool = p; FD_ZERO(&((*pollset)->readset)); FD_ZERO(&((*pollset)->writeset)); FD_ZERO(&((*pollset)->exceptset)); (*pollset)->maxfd = 0; #ifdef NETWARE (*pollset)->set_type = APR_NO_DESC; #endif (*pollset)->query_set = apr_palloc(p, size * sizeof(apr_pollfd_t)); (*pollset)->result_set = apr_palloc(p, size * sizeof(apr_pollfd_t)); return APR_SUCCESS; } APR_DECLARE(apr_status_t) apr_pollset_destroy(apr_pollset_t * pollset) { return APR_SUCCESS; } APR_DECLARE(apr_status_t) apr_pollset_add(apr_pollset_t *pollset, const apr_pollfd_t *descriptor) { apr_os_sock_t fd; if (pollset->nelts == pollset->nalloc) { return APR_ENOMEM; } pollset->query_set[pollset->nelts] = *descriptor; if (descriptor->desc_type == APR_POLL_SOCKET) { #ifdef NETWARE /* NetWare can't handle mixed descriptor types in select() */ if (HAS_PIPES(pollset->set_type)) { return APR_EBADF; } else { pollset->set_type = APR_POLL_SOCKET; } #endif fd = descriptor->desc.s->socketdes; } else { #if !APR_FILES_AS_SOCKETS return APR_EBADF; #else #ifdef NETWARE /* NetWare can't handle mixed descriptor types in select() */ if (descriptor->desc.f->is_pipe && !HAS_SOCKETS(pollset->set_type)) { pollset->set_type = APR_POLL_FILE; fd = descriptor->desc.f->filedes; } else { return APR_EBADF; } #else fd = descriptor->desc.f->filedes; #endif #endif } #if !defined(WIN32) && !defined(NETWARE) /* socket sets handled with array of handles */ if (fd >= FD_SETSIZE) { /* XXX invent new error code so application has a clue */ return APR_EBADF; } #endif if (descriptor->reqevents & APR_POLLIN) { FD_SET(fd, &(pollset->readset)); } if (descriptor->reqevents & APR_POLLOUT) { FD_SET(fd, &(pollset->writeset)); } if (descriptor->reqevents & (APR_POLLPRI | APR_POLLERR | APR_POLLHUP | APR_POLLNVAL)) { FD_SET(fd, &(pollset->exceptset)); } if ((int) fd > pollset->maxfd) { pollset->maxfd = (int) fd; } pollset->nelts++; return APR_SUCCESS; } APR_DECLARE(apr_status_t) apr_pollset_remove(apr_pollset_t * pollset, const apr_pollfd_t * descriptor) { apr_uint32_t i; apr_os_sock_t fd; if (descriptor->desc_type == APR_POLL_SOCKET) { fd = descriptor->desc.s->socketdes; } else { #if !APR_FILES_AS_SOCKETS return APR_EBADF; #else fd = descriptor->desc.f->filedes; #endif } for (i = 0; i < pollset->nelts; i++) { if (descriptor->desc.s == pollset->query_set[i].desc.s) { /* Found an instance of the fd: remove this and any other copies */ apr_uint32_t dst = i; apr_uint32_t old_nelts = pollset->nelts; pollset->nelts--; for (i++; i < old_nelts; i++) { if (descriptor->desc.s == pollset->query_set[i].desc.s) { pollset->nelts--; } else { pollset->query_set[dst] = pollset->query_set[i]; dst++; } } FD_CLR(fd, &(pollset->readset)); FD_CLR(fd, &(pollset->writeset)); FD_CLR(fd, &(pollset->exceptset)); if (((int) fd == pollset->maxfd) && (pollset->maxfd > 0)) { pollset->maxfd--; } return APR_SUCCESS; } } return APR_NOTFOUND; } APR_DECLARE(apr_status_t) apr_pollset_poll(apr_pollset_t *pollset, apr_interval_time_t timeout, apr_int32_t *num, const apr_pollfd_t **descriptors) { int rv; apr_uint32_t i, j; struct timeval tv, *tvptr; fd_set readset, writeset, exceptset; if (timeout < 0) { tvptr = NULL; } else { tv.tv_sec = (long) apr_time_sec(timeout); tv.tv_usec = (long) apr_time_usec(timeout); tvptr = &tv; } memcpy(&readset, &(pollset->readset), sizeof(fd_set)); memcpy(&writeset, &(pollset->writeset), sizeof(fd_set)); memcpy(&exceptset, &(pollset->exceptset), sizeof(fd_set)); #ifdef NETWARE if (HAS_PIPES(pollset->set_type)) { rv = pipe_select(pollset->maxfd + 1, &readset, &writeset, &exceptset, tvptr); } else #endif rv = select(pollset->maxfd + 1, &readset, &writeset, &exceptset, tvptr); (*num) = rv; if (rv < 0) { return apr_get_netos_error(); } if (rv == 0) { return APR_TIMEUP; } j = 0; for (i = 0; i < pollset->nelts; i++) { apr_os_sock_t fd; if (pollset->query_set[i].desc_type == APR_POLL_SOCKET) { fd = pollset->query_set[i].desc.s->socketdes; } else { #if !APR_FILES_AS_SOCKETS return APR_EBADF; #else fd = pollset->query_set[i].desc.f->filedes; #endif } if (FD_ISSET(fd, &readset) || FD_ISSET(fd, &writeset) || FD_ISSET(fd, &exceptset)) { pollset->result_set[j] = pollset->query_set[i]; pollset->result_set[j].rtnevents = 0; if (FD_ISSET(fd, &readset)) { pollset->result_set[j].rtnevents |= APR_POLLIN; } if (FD_ISSET(fd, &writeset)) { pollset->result_set[j].rtnevents |= APR_POLLOUT; } if (FD_ISSET(fd, &exceptset)) { pollset->result_set[j].rtnevents |= APR_POLLERR; } j++; } } (*num) = j; if (descriptors) *descriptors = pollset->result_set; return APR_SUCCESS; } #endif /* POLLSET_USES_SELECT */
001-log4cxx
trunk/src/apr/poll/unix/select.c
C
asf20
11,340
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "apr_arch_poll_private.h" #if defined(POLL_USES_POLL) || defined(POLLSET_USES_POLL) static apr_int16_t get_event(apr_int16_t event) { apr_int16_t rv = 0; if (event & APR_POLLIN) rv |= POLLIN; if (event & APR_POLLPRI) rv |= POLLPRI; if (event & APR_POLLOUT) rv |= POLLOUT; if (event & APR_POLLERR) rv |= POLLERR; if (event & APR_POLLHUP) rv |= POLLHUP; if (event & APR_POLLNVAL) rv |= POLLNVAL; return rv; } static apr_int16_t get_revent(apr_int16_t event) { apr_int16_t rv = 0; if (event & POLLIN) rv |= APR_POLLIN; if (event & POLLPRI) rv |= APR_POLLPRI; if (event & POLLOUT) rv |= APR_POLLOUT; if (event & POLLERR) rv |= APR_POLLERR; if (event & POLLHUP) rv |= APR_POLLHUP; if (event & POLLNVAL) rv |= APR_POLLNVAL; return rv; } #endif /* POLL_USES_POLL || POLLSET_USES_POLL */ #ifdef POLL_USES_POLL #define SMALL_POLLSET_LIMIT 8 APR_DECLARE(apr_status_t) apr_poll(apr_pollfd_t *aprset, apr_int32_t num, apr_int32_t *nsds, apr_interval_time_t timeout) { int i, num_to_poll; #ifdef HAVE_VLA /* XXX: I trust that this is a segv when insufficient stack exists? */ struct pollfd pollset[num]; #elif defined(HAVE_ALLOCA) struct pollfd *pollset = alloca(sizeof(struct pollfd) * num); if (!pollset) return APR_ENOMEM; #else struct pollfd tmp_pollset[SMALL_POLLSET_LIMIT]; struct pollfd *pollset; if (num <= SMALL_POLLSET_LIMIT) { pollset = tmp_pollset; } else { /* This does require O(n) to copy the descriptors to the internal * mapping. */ pollset = malloc(sizeof(struct pollfd) * num); /* The other option is adding an apr_pool_abort() fn to invoke * the pool's out of memory handler */ if (!pollset) return APR_ENOMEM; } #endif for (i = 0; i < num; i++) { if (aprset[i].desc_type == APR_POLL_SOCKET) { pollset[i].fd = aprset[i].desc.s->socketdes; } else if (aprset[i].desc_type == APR_POLL_FILE) { pollset[i].fd = aprset[i].desc.f->filedes; } else { break; } pollset[i].events = get_event(aprset[i].reqevents); } num_to_poll = i; if (timeout > 0) { timeout /= 1000; /* convert microseconds to milliseconds */ } i = poll(pollset, num_to_poll, timeout); (*nsds) = i; if (i > 0) { /* poll() sets revents only if an event was signalled; * we don't promise to set rtnevents unless an event * was signalled */ for (i = 0; i < num; i++) { aprset[i].rtnevents = get_revent(pollset[i].revents); } } #if !defined(HAVE_VLA) && !defined(HAVE_ALLOCA) if (num > SMALL_POLLSET_LIMIT) { free(pollset); } #endif if ((*nsds) < 0) { return apr_get_netos_error(); } if ((*nsds) == 0) { return APR_TIMEUP; } return APR_SUCCESS; } #endif /* POLL_USES_POLL */ #ifdef POLLSET_USES_POLL struct apr_pollset_t { apr_pool_t *pool; apr_uint32_t nelts; apr_uint32_t nalloc; struct pollfd *pollset; apr_pollfd_t *query_set; apr_pollfd_t *result_set; }; APR_DECLARE(apr_status_t) apr_pollset_create(apr_pollset_t **pollset, apr_uint32_t size, apr_pool_t *p, apr_uint32_t flags) { if (flags & APR_POLLSET_THREADSAFE) { *pollset = NULL; return APR_ENOTIMPL; } *pollset = apr_palloc(p, sizeof(**pollset)); (*pollset)->nelts = 0; (*pollset)->nalloc = size; (*pollset)->pool = p; (*pollset)->pollset = apr_palloc(p, size * sizeof(struct pollfd)); (*pollset)->query_set = apr_palloc(p, size * sizeof(apr_pollfd_t)); (*pollset)->result_set = apr_palloc(p, size * sizeof(apr_pollfd_t)); return APR_SUCCESS; } APR_DECLARE(apr_status_t) apr_pollset_destroy(apr_pollset_t *pollset) { return APR_SUCCESS; } APR_DECLARE(apr_status_t) apr_pollset_add(apr_pollset_t *pollset, const apr_pollfd_t *descriptor) { if (pollset->nelts == pollset->nalloc) { return APR_ENOMEM; } pollset->query_set[pollset->nelts] = *descriptor; if (descriptor->desc_type == APR_POLL_SOCKET) { pollset->pollset[pollset->nelts].fd = descriptor->desc.s->socketdes; } else { pollset->pollset[pollset->nelts].fd = descriptor->desc.f->filedes; } pollset->pollset[pollset->nelts].events = get_event(descriptor->reqevents); pollset->nelts++; return APR_SUCCESS; } APR_DECLARE(apr_status_t) apr_pollset_remove(apr_pollset_t *pollset, const apr_pollfd_t *descriptor) { apr_uint32_t i; for (i = 0; i < pollset->nelts; i++) { if (descriptor->desc.s == pollset->query_set[i].desc.s) { /* Found an instance of the fd: remove this and any other copies */ apr_uint32_t dst = i; apr_uint32_t old_nelts = pollset->nelts; pollset->nelts--; for (i++; i < old_nelts; i++) { if (descriptor->desc.s == pollset->query_set[i].desc.s) { pollset->nelts--; } else { pollset->pollset[dst] = pollset->pollset[i]; pollset->query_set[dst] = pollset->query_set[i]; dst++; } } return APR_SUCCESS; } } return APR_NOTFOUND; } APR_DECLARE(apr_status_t) apr_pollset_poll(apr_pollset_t *pollset, apr_interval_time_t timeout, apr_int32_t *num, const apr_pollfd_t **descriptors) { int rv; apr_uint32_t i, j; if (timeout > 0) { timeout /= 1000; } rv = poll(pollset->pollset, pollset->nelts, timeout); (*num) = rv; if (rv < 0) { return apr_get_netos_error(); } if (rv == 0) { return APR_TIMEUP; } j = 0; for (i = 0; i < pollset->nelts; i++) { if (pollset->pollset[i].revents != 0) { pollset->result_set[j] = pollset->query_set[i]; pollset->result_set[j].rtnevents = get_revent(pollset->pollset[i].revents); j++; } } if (descriptors) *descriptors = pollset->result_set; return APR_SUCCESS; } #endif /* POLLSET_USES_POLL */
001-log4cxx
trunk/src/apr/poll/unix/poll.c
C
asf20
7,643
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "apr_arch_poll_private.h" #ifdef POLLSET_USES_EPOLL static apr_int16_t get_epoll_event(apr_int16_t event) { apr_int16_t rv = 0; if (event & APR_POLLIN) rv |= EPOLLIN; if (event & APR_POLLPRI) rv |= EPOLLPRI; if (event & APR_POLLOUT) rv |= EPOLLOUT; if (event & APR_POLLERR) rv |= EPOLLERR; if (event & APR_POLLHUP) rv |= EPOLLHUP; /* APR_POLLNVAL is not handled by epoll. */ return rv; } static apr_int16_t get_epoll_revent(apr_int16_t event) { apr_int16_t rv = 0; if (event & EPOLLIN) rv |= APR_POLLIN; if (event & EPOLLPRI) rv |= APR_POLLPRI; if (event & EPOLLOUT) rv |= APR_POLLOUT; if (event & EPOLLERR) rv |= APR_POLLERR; if (event & EPOLLHUP) rv |= APR_POLLHUP; /* APR_POLLNVAL is not handled by epoll. */ return rv; } struct apr_pollset_t { apr_pool_t *pool; apr_uint32_t nelts; apr_uint32_t nalloc; int epoll_fd; struct epoll_event *pollset; apr_pollfd_t *result_set; apr_uint32_t flags; #if APR_HAS_THREADS /* A thread mutex to protect operations on the rings */ apr_thread_mutex_t *ring_lock; #endif /* A ring containing all of the pollfd_t that are active */ APR_RING_HEAD(pfd_query_ring_t, pfd_elem_t) query_ring; /* A ring of pollfd_t that have been used, and then _remove()'d */ APR_RING_HEAD(pfd_free_ring_t, pfd_elem_t) free_ring; /* A ring of pollfd_t where rings that have been _remove()`ed but might still be inside a _poll() */ APR_RING_HEAD(pfd_dead_ring_t, pfd_elem_t) dead_ring; }; static apr_status_t backend_cleanup(void *p_) { apr_pollset_t *pollset = (apr_pollset_t *) p_; close(pollset->epoll_fd); return APR_SUCCESS; } APR_DECLARE(apr_status_t) apr_pollset_create(apr_pollset_t **pollset, apr_uint32_t size, apr_pool_t *p, apr_uint32_t flags) { apr_status_t rv; int fd; fd = epoll_create(size); if (fd < 0) { *pollset = NULL; return errno; } *pollset = apr_palloc(p, sizeof(**pollset)); #if APR_HAS_THREADS if (flags & APR_POLLSET_THREADSAFE && ((rv = apr_thread_mutex_create(&(*pollset)->ring_lock, APR_THREAD_MUTEX_DEFAULT, p) != APR_SUCCESS))) { *pollset = NULL; return rv; } #else if (flags & APR_POLLSET_THREADSAFE) { *pollset = NULL; return APR_ENOTIMPL; } #endif (*pollset)->nelts = 0; (*pollset)->nalloc = size; (*pollset)->flags = flags; (*pollset)->pool = p; (*pollset)->epoll_fd = fd; (*pollset)->pollset = apr_palloc(p, size * sizeof(struct epoll_event)); apr_pool_cleanup_register(p, *pollset, backend_cleanup, backend_cleanup); (*pollset)->result_set = apr_palloc(p, size * sizeof(apr_pollfd_t)); APR_RING_INIT(&(*pollset)->query_ring, pfd_elem_t, link); APR_RING_INIT(&(*pollset)->free_ring, pfd_elem_t, link); APR_RING_INIT(&(*pollset)->dead_ring, pfd_elem_t, link); return APR_SUCCESS; } APR_DECLARE(apr_status_t) apr_pollset_destroy(apr_pollset_t *pollset) { return apr_pool_cleanup_run(pollset->pool, pollset, backend_cleanup); } APR_DECLARE(apr_status_t) apr_pollset_add(apr_pollset_t *pollset, const apr_pollfd_t *descriptor) { struct epoll_event ev; int ret = -1; pfd_elem_t *elem; apr_status_t rv = APR_SUCCESS; pollset_lock_rings(); if (!APR_RING_EMPTY(&(pollset->free_ring), pfd_elem_t, link)) { elem = APR_RING_FIRST(&(pollset->free_ring)); APR_RING_REMOVE(elem, link); } else { elem = (pfd_elem_t *) apr_palloc(pollset->pool, sizeof(pfd_elem_t)); APR_RING_ELEM_INIT(elem, link); } elem->pfd = *descriptor; ev.events = get_epoll_event(descriptor->reqevents); ev.data.ptr = elem; if (descriptor->desc_type == APR_POLL_SOCKET) { ret = epoll_ctl(pollset->epoll_fd, EPOLL_CTL_ADD, descriptor->desc.s->socketdes, &ev); } else { ret = epoll_ctl(pollset->epoll_fd, EPOLL_CTL_ADD, descriptor->desc.f->filedes, &ev); } if (0 != ret) { rv = APR_EBADF; APR_RING_INSERT_TAIL(&(pollset->free_ring), elem, pfd_elem_t, link); } else { pollset->nelts++; APR_RING_INSERT_TAIL(&(pollset->query_ring), elem, pfd_elem_t, link); } pollset_unlock_rings(); return rv; } APR_DECLARE(apr_status_t) apr_pollset_remove(apr_pollset_t *pollset, const apr_pollfd_t *descriptor) { pfd_elem_t *ep; apr_status_t rv = APR_SUCCESS; struct epoll_event ev; int ret = -1; pollset_lock_rings(); ev.events = get_epoll_event(descriptor->reqevents); if (descriptor->desc_type == APR_POLL_SOCKET) { ret = epoll_ctl(pollset->epoll_fd, EPOLL_CTL_DEL, descriptor->desc.s->socketdes, &ev); } else { ret = epoll_ctl(pollset->epoll_fd, EPOLL_CTL_DEL, descriptor->desc.f->filedes, &ev); } if (ret < 0) { rv = APR_NOTFOUND; } if (!APR_RING_EMPTY(&(pollset->query_ring), pfd_elem_t, link)) { for (ep = APR_RING_FIRST(&(pollset->query_ring)); ep != APR_RING_SENTINEL(&(pollset->query_ring), pfd_elem_t, link); ep = APR_RING_NEXT(ep, link)) { if (descriptor->desc.s == ep->pfd.desc.s) { APR_RING_REMOVE(ep, link); APR_RING_INSERT_TAIL(&(pollset->dead_ring), ep, pfd_elem_t, link); break; } } } pollset_unlock_rings(); return rv; } APR_DECLARE(apr_status_t) apr_pollset_poll(apr_pollset_t *pollset, apr_interval_time_t timeout, apr_int32_t *num, const apr_pollfd_t **descriptors) { int ret, i; apr_status_t rv = APR_SUCCESS; if (timeout > 0) { timeout /= 1000; } ret = epoll_wait(pollset->epoll_fd, pollset->pollset, pollset->nalloc, timeout); (*num) = ret; if (ret < 0) { rv = apr_get_netos_error(); } else if (ret == 0) { rv = APR_TIMEUP; } else { for (i = 0; i < ret; i++) { pollset->result_set[i] = (((pfd_elem_t *) (pollset->pollset[i].data.ptr))->pfd); pollset->result_set[i].rtnevents = get_epoll_revent(pollset->pollset[i].events); } if (descriptors) { *descriptors = pollset->result_set; } } pollset_lock_rings(); /* Shift all PFDs in the Dead Ring to be Free Ring */ APR_RING_CONCAT(&(pollset->free_ring), &(pollset->dead_ring), pfd_elem_t, link); pollset_unlock_rings(); return rv; } #endif /* POLLSET_USES_EPOLL */
001-log4cxx
trunk/src/apr/poll/unix/epoll.c
C
asf20
8,030
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "apr_arch_poll_private.h" #ifdef POLLSET_USES_PORT static apr_int16_t get_event(apr_int16_t event) { apr_int16_t rv = 0; if (event & APR_POLLIN) rv |= POLLIN; if (event & APR_POLLPRI) rv |= POLLPRI; if (event & APR_POLLOUT) rv |= POLLOUT; if (event & APR_POLLERR) rv |= POLLERR; if (event & APR_POLLHUP) rv |= POLLHUP; if (event & APR_POLLNVAL) rv |= POLLNVAL; return rv; } static apr_int16_t get_revent(apr_int16_t event) { apr_int16_t rv = 0; if (event & POLLIN) rv |= APR_POLLIN; if (event & POLLPRI) rv |= APR_POLLPRI; if (event & POLLOUT) rv |= APR_POLLOUT; if (event & POLLERR) rv |= APR_POLLERR; if (event & POLLHUP) rv |= APR_POLLHUP; if (event & POLLNVAL) rv |= APR_POLLNVAL; return rv; } struct apr_pollset_t { apr_pool_t *pool; apr_uint32_t nelts; apr_uint32_t nalloc; int port_fd; port_event_t *port_set; apr_pollfd_t *result_set; apr_uint32_t flags; #if APR_HAS_THREADS /* A thread mutex to protect operations on the rings */ apr_thread_mutex_t *ring_lock; #endif /* A ring containing all of the pollfd_t that are active */ APR_RING_HEAD(pfd_query_ring_t, pfd_elem_t) query_ring; APR_RING_HEAD(pfd_add_ring_t, pfd_elem_t) add_ring; /* A ring of pollfd_t that have been used, and then _remove'd */ APR_RING_HEAD(pfd_free_ring_t, pfd_elem_t) free_ring; /* A ring of pollfd_t where rings that have been _remove'd but might still be inside a _poll */ APR_RING_HEAD(pfd_dead_ring_t, pfd_elem_t) dead_ring; }; static apr_status_t backend_cleanup(void *p_) { apr_pollset_t *pollset = (apr_pollset_t *) p_; close(pollset->port_fd); return APR_SUCCESS; } APR_DECLARE(apr_status_t) apr_pollset_create(apr_pollset_t **pollset, apr_uint32_t size, apr_pool_t *p, apr_uint32_t flags) { apr_status_t rv = APR_SUCCESS; *pollset = apr_palloc(p, sizeof(**pollset)); #if APR_HAS_THREADS if (flags & APR_POLLSET_THREADSAFE && ((rv = apr_thread_mutex_create(&(*pollset)->ring_lock, APR_THREAD_MUTEX_DEFAULT, p) != APR_SUCCESS))) { *pollset = NULL; return rv; } #else if (flags & APR_POLLSET_THREADSAFE) { *pollset = NULL; return APR_ENOTIMPL; } #endif (*pollset)->nelts = 0; (*pollset)->nalloc = size; (*pollset)->flags = flags; (*pollset)->pool = p; (*pollset)->port_set = apr_palloc(p, size * sizeof(port_event_t)); (*pollset)->port_fd = port_create(); if ((*pollset)->port_fd < 0) { return APR_ENOMEM; } apr_pool_cleanup_register(p, (void *) (*pollset), backend_cleanup, apr_pool_cleanup_null); (*pollset)->result_set = apr_palloc(p, size * sizeof(apr_pollfd_t)); APR_RING_INIT(&(*pollset)->query_ring, pfd_elem_t, link); APR_RING_INIT(&(*pollset)->add_ring, pfd_elem_t, link); APR_RING_INIT(&(*pollset)->free_ring, pfd_elem_t, link); APR_RING_INIT(&(*pollset)->dead_ring, pfd_elem_t, link); return rv; } APR_DECLARE(apr_status_t) apr_pollset_destroy(apr_pollset_t *pollset) { return apr_pool_cleanup_run(pollset->pool, pollset, backend_cleanup); } APR_DECLARE(apr_status_t) apr_pollset_add(apr_pollset_t *pollset, const apr_pollfd_t *descriptor) { apr_os_sock_t fd; pfd_elem_t *elem; int res; apr_status_t rv = APR_SUCCESS; pollset_lock_rings(); if (!APR_RING_EMPTY(&(pollset->free_ring), pfd_elem_t, link)) { elem = APR_RING_FIRST(&(pollset->free_ring)); APR_RING_REMOVE(elem, link); } else { elem = (pfd_elem_t *) apr_palloc(pollset->pool, sizeof(pfd_elem_t)); APR_RING_ELEM_INIT(elem, link); } elem->pfd = *descriptor; if (descriptor->desc_type == APR_POLL_SOCKET) { fd = descriptor->desc.s->socketdes; } else { fd = descriptor->desc.f->filedes; } res = port_associate(pollset->port_fd, PORT_SOURCE_FD, fd, get_event(descriptor->reqevents), (void *)elem); if (res < 0) { rv = APR_ENOMEM; APR_RING_INSERT_TAIL(&(pollset->free_ring), elem, pfd_elem_t, link); } else { pollset->nelts++; APR_RING_INSERT_TAIL(&(pollset->query_ring), elem, pfd_elem_t, link); } pollset_unlock_rings(); return rv; } APR_DECLARE(apr_status_t) apr_pollset_remove(apr_pollset_t *pollset, const apr_pollfd_t *descriptor) { apr_os_sock_t fd; pfd_elem_t *ep; apr_status_t rv = APR_SUCCESS; int res; pollset_lock_rings(); if (descriptor->desc_type == APR_POLL_SOCKET) { fd = descriptor->desc.s->socketdes; } else { fd = descriptor->desc.f->filedes; } res = port_dissociate(pollset->port_fd, PORT_SOURCE_FD, fd); if (res < 0) { rv = APR_NOTFOUND; } if (!APR_RING_EMPTY(&(pollset->query_ring), pfd_elem_t, link)) { for (ep = APR_RING_FIRST(&(pollset->query_ring)); ep != APR_RING_SENTINEL(&(pollset->query_ring), pfd_elem_t, link); ep = APR_RING_NEXT(ep, link)) { if (descriptor->desc.s == ep->pfd.desc.s) { APR_RING_REMOVE(ep, link); APR_RING_INSERT_TAIL(&(pollset->dead_ring), ep, pfd_elem_t, link); break; } } } if (!APR_RING_EMPTY(&(pollset->add_ring), pfd_elem_t, link)) { for (ep = APR_RING_FIRST(&(pollset->add_ring)); ep != APR_RING_SENTINEL(&(pollset->add_ring), pfd_elem_t, link); ep = APR_RING_NEXT(ep, link)) { if (descriptor->desc.s == ep->pfd.desc.s) { APR_RING_REMOVE(ep, link); APR_RING_INSERT_TAIL(&(pollset->dead_ring), ep, pfd_elem_t, link); break; } } } pollset_unlock_rings(); return rv; } APR_DECLARE(apr_status_t) apr_pollset_poll(apr_pollset_t *pollset, apr_interval_time_t timeout, apr_int32_t *num, const apr_pollfd_t **descriptors) { apr_os_sock_t fd; int ret, i; unsigned int nget; pfd_elem_t *ep; struct timespec tv, *tvptr; apr_status_t rv = APR_SUCCESS; if (timeout < 0) { tvptr = NULL; } else { tv.tv_sec = (long) apr_time_sec(timeout); tv.tv_nsec = (long) apr_time_msec(timeout); tvptr = &tv; } nget = 1; pollset_lock_rings(); while (!APR_RING_EMPTY(&(pollset->add_ring), pfd_elem_t, link)) { ep = APR_RING_FIRST(&(pollset->add_ring)); APR_RING_REMOVE(ep, link); if (ep->pfd.desc_type == APR_POLL_SOCKET) { fd = ep->pfd.desc.s->socketdes; } else { fd = ep->pfd.desc.f->filedes; } port_associate(pollset->port_fd, PORT_SOURCE_FD, fd, get_event(ep->pfd.reqevents), ep); APR_RING_INSERT_TAIL(&(pollset->query_ring), ep, pfd_elem_t, link); } pollset_unlock_rings(); ret = port_getn(pollset->port_fd, pollset->port_set, pollset->nalloc, &nget, tvptr); (*num) = nget; if (ret == -1) { (*num) = 0; if (errno == ETIME || errno == EINTR) { rv = APR_TIMEUP; } else { rv = APR_EGENERAL; } } else if (nget == 0) { rv = APR_TIMEUP; } else { pollset_lock_rings(); for (i = 0; i < nget; i++) { pollset->result_set[i] = (((pfd_elem_t*)(pollset->port_set[i].portev_user))->pfd); pollset->result_set[i].rtnevents = get_revent(pollset->port_set[i].portev_events); APR_RING_REMOVE((pfd_elem_t*)pollset->port_set[i].portev_user, link); APR_RING_INSERT_TAIL(&(pollset->add_ring), (pfd_elem_t*)pollset->port_set[i].portev_user, pfd_elem_t, link); } pollset_unlock_rings(); if (descriptors) { *descriptors = pollset->result_set; } } pollset_lock_rings(); /* Shift all PFDs in the Dead Ring to be Free Ring */ APR_RING_CONCAT(&(pollset->free_ring), &(pollset->dead_ring), pfd_elem_t, link); pollset_unlock_rings(); return rv; } #endif /* POLLSET_USES_PORT */
001-log4cxx
trunk/src/apr/poll/unix/port.c
C
asf20
9,765
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "apr_arch_poll_private.h" #ifdef POLLSET_USES_KQUEUE static apr_int16_t get_kqueue_revent(apr_int16_t event, apr_int16_t flags) { apr_int16_t rv = 0; if (event == EVFILT_READ) rv |= APR_POLLIN; if (event == EVFILT_WRITE) rv |= APR_POLLOUT; if (flags & EV_EOF) rv |= APR_POLLHUP; if (flags & EV_ERROR) rv |= APR_POLLERR; return rv; } struct apr_pollset_t { apr_pool_t *pool; apr_uint32_t nelts; apr_uint32_t nalloc; int kqueue_fd; struct kevent kevent; struct kevent *ke_set; apr_pollfd_t *result_set; apr_uint32_t flags; #if APR_HAS_THREADS /* A thread mutex to protect operations on the rings */ apr_thread_mutex_t *ring_lock; #endif /* A ring containing all of the pollfd_t that are active */ APR_RING_HEAD(pfd_query_ring_t, pfd_elem_t) query_ring; /* A ring of pollfd_t that have been used, and then _remove'd */ APR_RING_HEAD(pfd_free_ring_t, pfd_elem_t) free_ring; /* A ring of pollfd_t where rings that have been _remove'd but might still be inside a _poll */ APR_RING_HEAD(pfd_dead_ring_t, pfd_elem_t) dead_ring; }; static apr_status_t backend_cleanup(void *p_) { apr_pollset_t *pollset = (apr_pollset_t *) p_; close(pollset->kqueue_fd); return APR_SUCCESS; } APR_DECLARE(apr_status_t) apr_pollset_create(apr_pollset_t **pollset, apr_uint32_t size, apr_pool_t *p, apr_uint32_t flags) { apr_status_t rv = APR_SUCCESS; *pollset = apr_palloc(p, sizeof(**pollset)); #if APR_HAS_THREADS if (flags & APR_POLLSET_THREADSAFE && ((rv = apr_thread_mutex_create(&(*pollset)->ring_lock, APR_THREAD_MUTEX_DEFAULT, p) != APR_SUCCESS))) { *pollset = NULL; return rv; } #else if (flags & APR_POLLSET_THREADSAFE) { *pollset = NULL; return APR_ENOTIMPL; } #endif (*pollset)->nelts = 0; (*pollset)->nalloc = size; (*pollset)->flags = flags; (*pollset)->pool = p; (*pollset)->ke_set = (struct kevent *) apr_palloc(p, size * sizeof(struct kevent)); memset((*pollset)->ke_set, 0, size * sizeof(struct kevent)); (*pollset)->kqueue_fd = kqueue(); if ((*pollset)->kqueue_fd == -1) { return APR_ENOMEM; } apr_pool_cleanup_register(p, (void *) (*pollset), backend_cleanup, apr_pool_cleanup_null); (*pollset)->result_set = apr_palloc(p, size * sizeof(apr_pollfd_t)); APR_RING_INIT(&(*pollset)->query_ring, pfd_elem_t, link); APR_RING_INIT(&(*pollset)->free_ring, pfd_elem_t, link); APR_RING_INIT(&(*pollset)->dead_ring, pfd_elem_t, link); return rv; } APR_DECLARE(apr_status_t) apr_pollset_destroy(apr_pollset_t * pollset) { return apr_pool_cleanup_run(pollset->pool, pollset, backend_cleanup); } APR_DECLARE(apr_status_t) apr_pollset_add(apr_pollset_t *pollset, const apr_pollfd_t *descriptor) { apr_os_sock_t fd; pfd_elem_t *elem; apr_status_t rv = APR_SUCCESS; pollset_lock_rings(); if (!APR_RING_EMPTY(&(pollset->free_ring), pfd_elem_t, link)) { elem = APR_RING_FIRST(&(pollset->free_ring)); APR_RING_REMOVE(elem, link); } else { elem = (pfd_elem_t *) apr_palloc(pollset->pool, sizeof(pfd_elem_t)); APR_RING_ELEM_INIT(elem, link); } elem->pfd = *descriptor; if (descriptor->desc_type == APR_POLL_SOCKET) { fd = descriptor->desc.s->socketdes; } else { fd = descriptor->desc.f->filedes; } if (descriptor->reqevents & APR_POLLIN) { EV_SET(&pollset->kevent, fd, EVFILT_READ, EV_ADD, 0, 0, elem); if (kevent(pollset->kqueue_fd, &pollset->kevent, 1, NULL, 0, NULL) == -1) { rv = APR_ENOMEM; } } if (descriptor->reqevents & APR_POLLOUT && rv == APR_SUCCESS) { EV_SET(&pollset->kevent, fd, EVFILT_WRITE, EV_ADD, 0, 0, elem); if (kevent(pollset->kqueue_fd, &pollset->kevent, 1, NULL, 0, NULL) == -1) { rv = APR_ENOMEM; } } if (rv == APR_SUCCESS) { pollset->nelts++; APR_RING_INSERT_TAIL(&(pollset->query_ring), elem, pfd_elem_t, link); } else { APR_RING_INSERT_TAIL(&(pollset->free_ring), elem, pfd_elem_t, link); } pollset_unlock_rings(); return rv; } APR_DECLARE(apr_status_t) apr_pollset_remove(apr_pollset_t *pollset, const apr_pollfd_t *descriptor) { pfd_elem_t *ep; apr_status_t rv = APR_SUCCESS; apr_os_sock_t fd; pollset_lock_rings(); if (descriptor->desc_type == APR_POLL_SOCKET) { fd = descriptor->desc.s->socketdes; } else { fd = descriptor->desc.f->filedes; } if (descriptor->reqevents & APR_POLLIN) { EV_SET(&pollset->kevent, fd, EVFILT_READ, EV_DELETE, 0, 0, NULL); if (kevent(pollset->kqueue_fd, &pollset->kevent, 1, NULL, 0, NULL) == -1) { rv = APR_NOTFOUND; } } if (descriptor->reqevents & APR_POLLOUT && rv == APR_SUCCESS) { EV_SET(&pollset->kevent, fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL); if (kevent(pollset->kqueue_fd, &pollset->kevent, 1, NULL, 0, NULL) == -1) { rv = APR_NOTFOUND; } } if (!APR_RING_EMPTY(&(pollset->query_ring), pfd_elem_t, link)) { for (ep = APR_RING_FIRST(&(pollset->query_ring)); ep != APR_RING_SENTINEL(&(pollset->query_ring), pfd_elem_t, link); ep = APR_RING_NEXT(ep, link)) { if (descriptor->desc.s == ep->pfd.desc.s) { APR_RING_REMOVE(ep, link); APR_RING_INSERT_TAIL(&(pollset->dead_ring), ep, pfd_elem_t, link); break; } } } pollset_unlock_rings(); return rv; } APR_DECLARE(apr_status_t) apr_pollset_poll(apr_pollset_t *pollset, apr_interval_time_t timeout, apr_int32_t *num, const apr_pollfd_t **descriptors) { int ret, i; struct timespec tv, *tvptr; apr_status_t rv = APR_SUCCESS; if (timeout < 0) { tvptr = NULL; } else { tv.tv_sec = (long) apr_time_sec(timeout); tv.tv_nsec = (long) apr_time_msec(timeout); tvptr = &tv; } ret = kevent(pollset->kqueue_fd, NULL, 0, pollset->ke_set, pollset->nalloc, tvptr); (*num) = ret; if (ret < 0) { rv = apr_get_netos_error(); } else if (ret == 0) { rv = APR_TIMEUP; } else { for (i = 0; i < ret; i++) { pollset->result_set[i] = (((pfd_elem_t*)(pollset->ke_set[i].udata))->pfd); pollset->result_set[i].rtnevents = get_kqueue_revent(pollset->ke_set[i].filter, pollset->ke_set[i].flags); } if (descriptors) { *descriptors = pollset->result_set; } } pollset_lock_rings(); /* Shift all PFDs in the Dead Ring to be Free Ring */ APR_RING_CONCAT(&(pollset->free_ring), &(pollset->dead_ring), pfd_elem_t, link); pollset_unlock_rings(); return rv; } #endif /* POLLSET_USES_KQUEUE */
001-log4cxx
trunk/src/apr/poll/unix/kqueue.c
C
asf20
8,462
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "apr.h" #include "apr_poll.h" #include "apr_arch_networkio.h" APR_DECLARE(apr_status_t) apr_poll(apr_pollfd_t *aprset, apr_int32_t num, apr_int32_t *nsds, apr_interval_time_t timeout) { int *pollset; int i; int num_read = 0, num_write = 0, num_except = 0, num_total; int pos_read, pos_write, pos_except; for (i = 0; i < num; i++) { if (aprset[i].desc_type == APR_POLL_SOCKET) { num_read += (aprset[i].reqevents & APR_POLLIN) != 0; num_write += (aprset[i].reqevents & APR_POLLOUT) != 0; num_except += (aprset[i].reqevents & APR_POLLPRI) != 0; } } num_total = num_read + num_write + num_except; pollset = alloca(sizeof(int) * num_total); memset(pollset, 0, sizeof(int) * num_total); pos_read = 0; pos_write = num_read; pos_except = pos_write + num_write; for (i = 0; i < num; i++) { if (aprset[i].desc_type == APR_POLL_SOCKET) { if (aprset[i].reqevents & APR_POLLIN) { pollset[pos_read++] = aprset[i].desc.s->socketdes; } if (aprset[i].reqevents & APR_POLLOUT) { pollset[pos_write++] = aprset[i].desc.s->socketdes; } if (aprset[i].reqevents & APR_POLLPRI) { pollset[pos_except++] = aprset[i].desc.s->socketdes; } aprset[i].rtnevents = 0; } } if (timeout > 0) { timeout /= 1000; /* convert microseconds to milliseconds */ } i = select(pollset, num_read, num_write, num_except, timeout); (*nsds) = i; if ((*nsds) < 0) { return APR_FROM_OS_ERROR(sock_errno()); } if ((*nsds) == 0) { return APR_TIMEUP; } pos_read = 0; pos_write = num_read; pos_except = pos_write + num_write; for (i = 0; i < num; i++) { if (aprset[i].desc_type == APR_POLL_SOCKET) { if (aprset[i].reqevents & APR_POLLIN) { if (pollset[pos_read++] > 0) { aprset[i].rtnevents |= APR_POLLIN; } } if (aprset[i].reqevents & APR_POLLOUT) { if (pollset[pos_write++] > 0) { aprset[i].rtnevents |= APR_POLLOUT; } } if (aprset[i].reqevents & APR_POLLPRI) { if (pollset[pos_except++] > 0) { aprset[i].rtnevents |= APR_POLLPRI; } } } } return APR_SUCCESS; }
001-log4cxx
trunk/src/apr/poll/os2/poll.c
C
asf20
3,336
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "apr.h" #include "apr_poll.h" #include "apr_arch_networkio.h" struct apr_pollset_t { apr_pool_t *pool; apr_uint32_t nelts; apr_uint32_t nalloc; int *pollset; int num_read; int num_write; int num_except; int num_total; apr_pollfd_t *query_set; apr_pollfd_t *result_set; }; APR_DECLARE(apr_status_t) apr_pollset_create(apr_pollset_t **pollset, apr_uint32_t size, apr_pool_t *p, apr_uint32_t flags) { *pollset = apr_palloc(p, sizeof(**pollset)); (*pollset)->pool = p; (*pollset)->nelts = 0; (*pollset)->nalloc = size; (*pollset)->pollset = apr_palloc(p, size * sizeof(int) * 3); (*pollset)->query_set = apr_palloc(p, size * sizeof(apr_pollfd_t)); (*pollset)->result_set = apr_palloc(p, size * sizeof(apr_pollfd_t)); (*pollset)->num_read = -1; return APR_SUCCESS; } APR_DECLARE(apr_status_t) apr_pollset_destroy(apr_pollset_t *pollset) { /* A no-op function for now. If we later implement /dev/poll * support, we'll need to close the /dev/poll fd here */ return APR_SUCCESS; } APR_DECLARE(apr_status_t) apr_pollset_add(apr_pollset_t *pollset, const apr_pollfd_t *descriptor) { if (pollset->nelts == pollset->nalloc) { return APR_ENOMEM; } pollset->query_set[pollset->nelts] = *descriptor; if (descriptor->desc_type != APR_POLL_SOCKET) { return APR_EBADF; } pollset->nelts++; pollset->num_read = -1; return APR_SUCCESS; } APR_DECLARE(apr_status_t) apr_pollset_remove(apr_pollset_t *pollset, const apr_pollfd_t *descriptor) { apr_uint32_t i; for (i = 0; i < pollset->nelts; i++) { if (descriptor->desc.s == pollset->query_set[i].desc.s) { /* Found an instance of the fd: remove this and any other copies */ apr_uint32_t dst = i; apr_uint32_t old_nelts = pollset->nelts; pollset->nelts--; for (i++; i < old_nelts; i++) { if (descriptor->desc.s == pollset->query_set[i].desc.s) { pollset->nelts--; } else { pollset->pollset[dst] = pollset->pollset[i]; pollset->query_set[dst] = pollset->query_set[i]; dst++; } } pollset->num_read = -1; return APR_SUCCESS; } } return APR_NOTFOUND; } static void make_pollset(apr_pollset_t *pollset) { int i; int pos = 0; pollset->num_read = 0; pollset->num_write = 0; pollset->num_except = 0; for (i = 0; i < pollset->nelts; i++) { if (pollset->query_set[i].reqevents & APR_POLLIN) { pollset->pollset[pos++] = pollset->query_set[i].desc.s->socketdes; pollset->num_read++; } } for (i = 0; i < pollset->nelts; i++) { if (pollset->query_set[i].reqevents & APR_POLLOUT) { pollset->pollset[pos++] = pollset->query_set[i].desc.s->socketdes; pollset->num_write++; } } for (i = 0; i < pollset->nelts; i++) { if (pollset->query_set[i].reqevents & APR_POLLPRI) { pollset->pollset[pos++] = pollset->query_set[i].desc.s->socketdes; pollset->num_except++; } } pollset->num_total = pollset->num_read + pollset->num_write + pollset->num_except; } APR_DECLARE(apr_status_t) apr_pollset_poll(apr_pollset_t *pollset, apr_interval_time_t timeout, apr_int32_t *num, const apr_pollfd_t **descriptors) { int rv; apr_uint32_t i; int *pollresult; int read_pos, write_pos, except_pos; if (pollset->num_read < 0) { make_pollset(pollset); } pollresult = alloca(sizeof(int) * pollset->num_total); memcpy(pollresult, pollset->pollset, sizeof(int) * pollset->num_total); (*num) = 0; if (timeout > 0) { timeout /= 1000; } rv = select(pollresult, pollset->num_read, pollset->num_write, pollset->num_except, timeout); if (rv < 0) { return APR_FROM_OS_ERROR(sock_errno()); } if (rv == 0) { return APR_TIMEUP; } read_pos = 0; write_pos = pollset->num_read; except_pos = pollset->num_read + pollset->num_write; for (i = 0; i < pollset->nelts; i++) { int rtnevents = 0; if (pollset->query_set[i].reqevents & APR_POLLIN) { if (pollresult[read_pos++] != -1) { rtnevents |= APR_POLLIN; } } if (pollset->query_set[i].reqevents & APR_POLLOUT) { if (pollresult[write_pos++] != -1) { rtnevents |= APR_POLLOUT; } } if (pollset->query_set[i].reqevents & APR_POLLPRI) { if (pollresult[except_pos++] != -1) { rtnevents |= APR_POLLPRI; } } if (rtnevents) { pollset->result_set[*num] = pollset->query_set[i]; pollset->result_set[*num].rtnevents = rtnevents; (*num)++; } } if (descriptors) { *descriptors = pollset->result_set; } return APR_SUCCESS; }
001-log4cxx
trunk/src/apr/poll/os2/pollset.c
C
asf20
6,280
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef APR_INHERIT_H #define APR_INHERIT_H /** * @file apr_inherit.h * @brief APR File Handle Inheritance Helpers * @remark This internal header includes internal declaration helpers * for other headers to declare apr_foo_inherit_[un]set functions. */ /** * Prototype for type-specific declarations of apr_foo_inherit_set * functions. * @remark Doxygen unwraps this macro (via doxygen.conf) to provide * actual help for each specific occurance of apr_foo_inherit_set. * @remark the linkage is specified for APR. It would be possible to expand * the macros to support other linkages. */ #define APR_DECLARE_INHERIT_SET(type) \ APR_DECLARE(apr_status_t) apr_##type##_inherit_set( \ apr_##type##_t *the##type) /** * Prototype for type-specific declarations of apr_foo_inherit_unset * functions. * @remark Doxygen unwraps this macro (via doxygen.conf) to provide * actual help for each specific occurance of apr_foo_inherit_unset. * @remark the linkage is specified for APR. It would be possible to expand * the macros to support other linkages. */ #define APR_DECLARE_INHERIT_UNSET(type) \ APR_DECLARE(apr_status_t) apr_##type##_inherit_unset( \ apr_##type##_t *the##type) #endif /* ! APR_INHERIT_H */
001-log4cxx
trunk/src/apr/include/apr_inherit.h
C
asf20
2,137
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef APR_TIME_H #define APR_TIME_H /** * @file apr_time.h * @brief APR Time Library */ #include "apr.h" #include "apr_pools.h" #include "apr_errno.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /** * @defgroup apr_time Time Routines * @ingroup APR * @{ */ /** month names */ APR_DECLARE_DATA extern const char apr_month_snames[12][4]; /** day names */ APR_DECLARE_DATA extern const char apr_day_snames[7][4]; /** number of microseconds since 00:00:00 january 1, 1970 UTC */ typedef apr_int64_t apr_time_t; /** mechanism to properly type apr_time_t literals */ #define APR_TIME_C(val) APR_INT64_C(val) /** mechanism to properly print apr_time_t values */ #define APR_TIME_T_FMT APR_INT64_T_FMT /** intervals for I/O timeouts, in microseconds */ typedef apr_int64_t apr_interval_time_t; /** short interval for I/O timeouts, in microseconds */ typedef apr_int32_t apr_short_interval_time_t; /** number of microseconds per second */ #define APR_USEC_PER_SEC APR_TIME_C(1000000) /** @return apr_time_t as a second */ #define apr_time_sec(time) ((time) / APR_USEC_PER_SEC) /** @return apr_time_t as a usec */ #define apr_time_usec(time) ((time) % APR_USEC_PER_SEC) /** @return apr_time_t as a msec */ #define apr_time_msec(time) (((time) / 1000) % 1000) /** @return apr_time_t as a msec */ #define apr_time_as_msec(time) ((time) / 1000) /** @return a second as an apr_time_t */ #define apr_time_from_sec(sec) ((apr_time_t)(sec) * APR_USEC_PER_SEC) /** @return a second and usec combination as an apr_time_t */ #define apr_time_make(sec, usec) ((apr_time_t)(sec) * APR_USEC_PER_SEC \ + (apr_time_t)(usec)) /** * @return the current time */ APR_DECLARE(apr_time_t) apr_time_now(void); /** @see apr_time_exp_t */ typedef struct apr_time_exp_t apr_time_exp_t; /** * a structure similar to ANSI struct tm with the following differences: * - tm_usec isn't an ANSI field * - tm_gmtoff isn't an ANSI field (it's a bsdism) */ struct apr_time_exp_t { /** microseconds past tm_sec */ apr_int32_t tm_usec; /** (0-61) seconds past tm_min */ apr_int32_t tm_sec; /** (0-59) minutes past tm_hour */ apr_int32_t tm_min; /** (0-23) hours past midnight */ apr_int32_t tm_hour; /** (1-31) day of the month */ apr_int32_t tm_mday; /** (0-11) month of the year */ apr_int32_t tm_mon; /** year since 1900 */ apr_int32_t tm_year; /** (0-6) days since sunday */ apr_int32_t tm_wday; /** (0-365) days since jan 1 */ apr_int32_t tm_yday; /** daylight saving time */ apr_int32_t tm_isdst; /** seconds east of UTC */ apr_int32_t tm_gmtoff; }; /** * convert an ansi time_t to an apr_time_t * @param result the resulting apr_time_t * @param input the time_t to convert */ APR_DECLARE(apr_status_t) apr_time_ansi_put(apr_time_t *result, time_t input); /** * convert a time to its human readable components using an offset * from GMT * @param result the exploded time * @param input the time to explode * @param offs the number of seconds offset to apply */ APR_DECLARE(apr_status_t) apr_time_exp_tz(apr_time_exp_t *result, apr_time_t input, apr_int32_t offs); /** * convert a time to its human readable components in GMT timezone * @param result the exploded time * @param input the time to explode */ APR_DECLARE(apr_status_t) apr_time_exp_gmt(apr_time_exp_t *result, apr_time_t input); /** * convert a time to its human readable components in local timezone * @param result the exploded time * @param input the time to explode */ APR_DECLARE(apr_status_t) apr_time_exp_lt(apr_time_exp_t *result, apr_time_t input); /** * Convert time value from human readable format to a numeric apr_time_t * e.g. elapsed usec since epoch * @param result the resulting imploded time * @param input the input exploded time */ APR_DECLARE(apr_status_t) apr_time_exp_get(apr_time_t *result, apr_time_exp_t *input); /** * Convert time value from human readable format to a numeric apr_time_t that * always represents GMT * @param result the resulting imploded time * @param input the input exploded time */ APR_DECLARE(apr_status_t) apr_time_exp_gmt_get(apr_time_t *result, apr_time_exp_t *input); /** * Sleep for the specified number of micro-seconds. * @param t desired amount of time to sleep. * @warning May sleep for longer than the specified time. */ APR_DECLARE(void) apr_sleep(apr_interval_time_t t); /** length of a RFC822 Date */ #define APR_RFC822_DATE_LEN (30) /** * apr_rfc822_date formats dates in the RFC822 * format in an efficient manner. It is a fixed length * format which requires the indicated amount of storage, * including the trailing NUL terminator. * @param date_str String to write to. * @param t the time to convert */ APR_DECLARE(apr_status_t) apr_rfc822_date(char *date_str, apr_time_t t); /** length of a CTIME date */ #define APR_CTIME_LEN (25) /** * apr_ctime formats dates in the ctime() format * in an efficient manner. it is a fixed length format * and requires the indicated amount of storage including * the trailing NUL terminator. * Unlike ANSI/ISO C ctime(), apr_ctime() does not include * a \n at the end of the string. * @param date_str String to write to. * @param t the time to convert */ APR_DECLARE(apr_status_t) apr_ctime(char *date_str, apr_time_t t); /** * formats the exploded time according to the format specified * @param s string to write to * @param retsize The length of the returned string * @param max The maximum length of the string * @param format The format for the time string * @param tm The time to convert */ APR_DECLARE(apr_status_t) apr_strftime(char *s, apr_size_t *retsize, apr_size_t max, const char *format, apr_time_exp_t *tm); /** * Improve the clock resolution for the lifetime of the given pool. * Generally this is only desireable on benchmarking and other very * time-sensitive applications, and has no impact on most platforms. * @param p The pool to associate the finer clock resolution */ APR_DECLARE(void) apr_time_clock_hires(apr_pool_t *p); /** @} */ #ifdef __cplusplus } #endif #endif /* ! APR_TIME_H */
001-log4cxx
trunk/src/apr/include/apr_time.h
C
asf20
7,385
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef APR_USER_H #define APR_USER_H /** * @file apr_user.h * @brief APR User ID Services */ #include "apr.h" #include "apr_errno.h" #include "apr_pools.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /** * @defgroup apr_user User and Group ID Services * @ingroup APR * @{ */ /** * Structure for determining user ownership. */ #ifdef WIN32 typedef PSID apr_uid_t; #else typedef uid_t apr_uid_t; #endif /** * Structure for determining group ownership. */ #ifdef WIN32 typedef PSID apr_gid_t; #else typedef gid_t apr_gid_t; #endif #if APR_HAS_USER /** * Get the userid (and groupid) of the calling process * @param userid Returns the user id * @param groupid Returns the user's group id * @param p The pool from which to allocate working space * @remark This function is available only if APR_HAS_USER is defined. */ APR_DECLARE(apr_status_t) apr_uid_current(apr_uid_t *userid, apr_gid_t *groupid, apr_pool_t *p); /** * Get the user name for a specified userid * @param username Pointer to new string containing user name (on output) * @param userid The userid * @param p The pool from which to allocate the string * @remark This function is available only if APR_HAS_USER is defined. */ APR_DECLARE(apr_status_t) apr_uid_name_get(char **username, apr_uid_t userid, apr_pool_t *p); /** * Get the userid (and groupid) for the specified username * @param userid Returns the user id * @param groupid Returns the user's group id * @param username The username to lookup * @param p The pool from which to allocate working space * @remark This function is available only if APR_HAS_USER is defined. */ APR_DECLARE(apr_status_t) apr_uid_get(apr_uid_t *userid, apr_gid_t *groupid, const char *username, apr_pool_t *p); /** * Get the home directory for the named user * @param dirname Pointer to new string containing directory name (on output) * @param username The named user * @param p The pool from which to allocate the string * @remark This function is available only if APR_HAS_USER is defined. */ APR_DECLARE(apr_status_t) apr_uid_homepath_get(char **dirname, const char *username, apr_pool_t *p); /** * Compare two user identifiers for equality. * @param left One uid to test * @param right Another uid to test * @return APR_SUCCESS if the apr_uid_t strutures identify the same user, * APR_EMISMATCH if not, APR_BADARG if an apr_uid_t is invalid. * @remark This function is available only if APR_HAS_USER is defined. */ #if defined(WIN32) APR_DECLARE(apr_status_t) apr_uid_compare(apr_uid_t left, apr_uid_t right); #else #define apr_uid_compare(left,right) (((left) == (right)) ? APR_SUCCESS : APR_EMISMATCH) #endif /** * Get the group name for a specified groupid * @param groupname Pointer to new string containing group name (on output) * @param groupid The groupid * @param p The pool from which to allocate the string * @remark This function is available only if APR_HAS_USER is defined. */ APR_DECLARE(apr_status_t) apr_gid_name_get(char **groupname, apr_gid_t groupid, apr_pool_t *p); /** * Get the groupid for a specified group name * @param groupid Pointer to the group id (on output) * @param groupname The group name to look up * @param p The pool from which to allocate the string * @remark This function is available only if APR_HAS_USER is defined. */ APR_DECLARE(apr_status_t) apr_gid_get(apr_gid_t *groupid, const char *groupname, apr_pool_t *p); /** * Compare two group identifiers for equality. * @param left One gid to test * @param right Another gid to test * @return APR_SUCCESS if the apr_gid_t strutures identify the same group, * APR_EMISMATCH if not, APR_BADARG if an apr_gid_t is invalid. * @remark This function is available only if APR_HAS_USER is defined. */ #if defined(WIN32) APR_DECLARE(apr_status_t) apr_gid_compare(apr_gid_t left, apr_gid_t right); #else #define apr_gid_compare(left,right) (((left) == (right)) ? APR_SUCCESS : APR_EMISMATCH) #endif #endif /* ! APR_HAS_USER */ /** @} */ #ifdef __cplusplus } #endif #endif /* ! APR_USER_H */
001-log4cxx
trunk/src/apr/include/apr_user.h
C
asf20
5,307
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef APR_FILE_IO_H #define APR_FILE_IO_H /** * @file apr_file_io.h * @brief APR File I/O Handling */ #include "apr.h" #include "apr_pools.h" #include "apr_time.h" #include "apr_errno.h" #include "apr_file_info.h" #include "apr_inherit.h" #define APR_WANT_STDIO /**< for SEEK_* */ #define APR_WANT_IOVEC /**< for apr_file_writev */ #include "apr_want.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /** * @defgroup apr_file_io File I/O Handling Functions * @ingroup APR * @{ */ /** * @defgroup apr_file_open_flags File Open Flags/Routines * @{ */ /* Note to implementors: Values in the range 0x00100000--0x80000000 are reserved for platform-specific values. */ #define APR_FOPEN_READ 0x00001 /**< Open the file for reading */ #define APR_FOPEN_WRITE 0x00002 /**< Open the file for writing */ #define APR_FOPEN_CREATE 0x00004 /**< Create the file if not there */ #define APR_FOPEN_APPEND 0x00008 /**< Append to the end of the file */ #define APR_FOPEN_TRUNCATE 0x00010 /**< Open the file and truncate to 0 length */ #define APR_FOPEN_BINARY 0x00020 /**< Open the file in binary mode */ #define APR_FOPEN_EXCL 0x00040 /**< Open should fail if APR_CREATE and file exists. */ #define APR_FOPEN_BUFFERED 0x00080 /**< Open the file for buffered I/O */ #define APR_FOPEN_DELONCLOSE 0x00100 /**< Delete the file after close */ #define APR_FOPEN_XTHREAD 0x00200 /**< Platform dependent tag to open the file for use across multiple threads */ #define APR_FOPEN_SHARELOCK 0x00400 /**< Platform dependent support for higher level locked read/write access to support writes across process/machines */ #define APR_FOPEN_NOCLEANUP 0x00800 /**< Do not register a cleanup when the file is opened */ #define APR_FOPEN_SENDFILE_ENABLED 0x01000 /**< Advisory flag that this file should support apr_socket_sendfile operation */ #define APR_FOPEN_LARGEFILE 0x04000 /**< Platform dependent flag to enable large file support; WARNING see below. */ /* backcompat */ #define APR_READ APR_FOPEN_READ /**< @deprecated @see APR_FOPEN_READ */ #define APR_WRITE APR_FOPEN_WRITE /**< @deprecated @see APR_FOPEN_WRITE */ #define APR_CREATE APR_FOPEN_CREATE /**< @deprecated @see APR_FOPEN_CREATE */ #define APR_APPEND APR_FOPEN_APPEND /**< @deprecated @see APR_FOPEN_APPEND */ #define APR_TRUNCATE APR_FOPEN_TRUNCATE /**< @deprecated @see APR_FOPEN_TRUNCATE */ #define APR_BINARY APR_FOPEN_BINARY /**< @deprecated @see APR_FOPEN_BINARY */ #define APR_EXCL APR_FOPEN_EXCL /**< @deprecated @see APR_FOPEN_EXCL */ #define APR_BUFFERED APR_FOPEN_BUFFERED /**< @deprecated @see APR_FOPEN_BUFFERED */ #define APR_DELONCLOSE APR_FOPEN_DELONCLOSE /**< @deprecated @see APR_FOPEN_DELONCLOSE */ #define APR_XTHREAD APR_FOPEN_XTHREAD /**< @deprecated @see APR_FOPEN_XTHREAD */ #define APR_SHARELOCK APR_FOPEN_SHARELOCK /**< @deprecated @see APR_FOPEN_SHARELOCK */ #define APR_FILE_NOCLEANUP APR_FOPEN_NOCLEANUP /**< @deprecated @see APR_FOPEN_NOCLEANUP */ #define APR_SENDFILE_ENABLED APR_FOPEN_SENDFILE_ENABLED /**< @deprecated @see APR_FOPEN_SENDFILE_ENABLED */ #define APR_LARGEFILE APR_FOPEN_LARGEFILE /**< @deprecated @see APR_FOPEN_LARGEFILE */ /** @warning The APR_LARGEFILE flag only has effect on some platforms * where sizeof(apr_off_t) == 4. Where implemented, it allows opening * and writing to a file which exceeds the size which can be * represented by apr_off_t (2 gigabytes). When a file's size does * exceed 2Gb, apr_file_info_get() will fail with an error on the * descriptor, likewise apr_stat()/apr_lstat() will fail on the * filename. apr_dir_read() will fail with APR_INCOMPLETE on a * directory entry for a large file depending on the particular * APR_FINFO_* flags. Generally, it is not recommended to use this * flag. */ /** @} */ /** * @defgroup apr_file_seek_flags File Seek Flags * @{ */ /* flags for apr_file_seek */ /** Set the file position */ #define APR_SET SEEK_SET /** Current */ #define APR_CUR SEEK_CUR /** Go to end of file */ #define APR_END SEEK_END /** @} */ /** * @defgroup apr_file_attrs_set_flags File Attribute Flags * @{ */ /* flags for apr_file_attrs_set */ #define APR_FILE_ATTR_READONLY 0x01 /**< File is read-only */ #define APR_FILE_ATTR_EXECUTABLE 0x02 /**< File is executable */ #define APR_FILE_ATTR_HIDDEN 0x04 /**< File is hidden */ /** @} */ /** * @defgroup apr_file_writev{_full} max iovec size * @{ */ #if defined(DOXYGEN) #define APR_MAX_IOVEC_SIZE 1024 /**< System dependent maximum size of an iovec array */ #elif defined(IOV_MAX) #define APR_MAX_IOVEC_SIZE IOV_MAX #elif defined(MAX_IOVEC) #define APR_MAX_IOVEC_SIZE MAX_IOVEC #else #define APR_MAX_IOVEC_SIZE 1024 #endif /** @} */ /** File attributes */ typedef apr_uint32_t apr_fileattrs_t; /** Type to pass as whence argument to apr_file_seek. */ typedef int apr_seek_where_t; /** * Structure for referencing files. */ typedef struct apr_file_t apr_file_t; /* File lock types/flags */ /** * @defgroup apr_file_lock_types File Lock Types * @{ */ #define APR_FLOCK_SHARED 1 /**< Shared lock. More than one process or thread can hold a shared lock at any given time. Essentially, this is a "read lock", preventing writers from establishing an exclusive lock. */ #define APR_FLOCK_EXCLUSIVE 2 /**< Exclusive lock. Only one process may hold an exclusive lock at any given time. This is analogous to a "write lock". */ #define APR_FLOCK_TYPEMASK 0x000F /**< mask to extract lock type */ #define APR_FLOCK_NONBLOCK 0x0010 /**< do not block while acquiring the file lock */ /** @} */ /** * Open the specified file. * @param newf The opened file descriptor. * @param fname The full path to the file (using / on all systems) * @param flag Or'ed value of: * <PRE> * APR_READ open for reading * APR_WRITE open for writing * APR_CREATE create the file if not there * APR_APPEND file ptr is set to end prior to all writes * APR_TRUNCATE set length to zero if file exists * APR_BINARY not a text file (This flag is ignored on * UNIX because it has no meaning) * APR_BUFFERED buffer the data. Default is non-buffered * APR_EXCL return error if APR_CREATE and file exists * APR_DELONCLOSE delete the file after closing. * APR_XTHREAD Platform dependent tag to open the file * for use across multiple threads * APR_SHARELOCK Platform dependent support for higher * level locked read/write access to support * writes across process/machines * APR_FILE_NOCLEANUP Do not register a cleanup with the pool * passed in on the <EM>pool</EM> argument (see below). * The apr_os_file_t handle in apr_file_t will not * be closed when the pool is destroyed. * APR_SENDFILE_ENABLED Open with appropriate platform semantics * for sendfile operations. Advisory only, * apr_socket_sendfile does not check this flag. * </PRE> * @param perm Access permissions for file. * @param pool The pool to use. * @remark If perm is APR_OS_DEFAULT and the file is being created, * appropriate default permissions will be used. * @remark By default, the returned file descriptor will not be * inherited by child processes created by apr_proc_create(). This * can be changed using apr_file_inherit_set(). */ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **newf, const char *fname, apr_int32_t flag, apr_fileperms_t perm, apr_pool_t *pool); /** * Close the specified file. * @param file The file descriptor to close. */ APR_DECLARE(apr_status_t) apr_file_close(apr_file_t *file); /** * Delete the specified file. * @param path The full path to the file (using / on all systems) * @param pool The pool to use. * @remark If the file is open, it won't be removed until all * instances are closed. */ APR_DECLARE(apr_status_t) apr_file_remove(const char *path, apr_pool_t *pool); /** * Rename the specified file. * @param from_path The full path to the original file (using / on all systems) * @param to_path The full path to the new file (using / on all systems) * @param pool The pool to use. * @warning If a file exists at the new location, then it will be * overwritten. Moving files or directories across devices may not be * possible. */ APR_DECLARE(apr_status_t) apr_file_rename(const char *from_path, const char *to_path, apr_pool_t *pool); /** * Copy the specified file to another file. * @param from_path The full path to the original file (using / on all systems) * @param to_path The full path to the new file (using / on all systems) * @param perms Access permissions for the new file if it is created. * In place of the usual or'd combination of file permissions, the * value APR_FILE_SOURCE_PERMS may be given, in which case the source * file's permissions are copied. * @param pool The pool to use. * @remark The new file does not need to exist, it will be created if required. * @warning If the new file already exists, its contents will be overwritten. */ APR_DECLARE(apr_status_t) apr_file_copy(const char *from_path, const char *to_path, apr_fileperms_t perms, apr_pool_t *pool); /** * Append the specified file to another file. * @param from_path The full path to the source file (use / on all systems) * @param to_path The full path to the destination file (use / on all systems) * @param perms Access permissions for the destination file if it is created. * In place of the usual or'd combination of file permissions, the * value APR_FILE_SOURCE_PERMS may be given, in which case the source * file's permissions are copied. * @param pool The pool to use. * @remark The new file does not need to exist, it will be created if required. */ APR_DECLARE(apr_status_t) apr_file_append(const char *from_path, const char *to_path, apr_fileperms_t perms, apr_pool_t *pool); /** * Are we at the end of the file * @param fptr The apr file we are testing. * @remark Returns APR_EOF if we are at the end of file, APR_SUCCESS otherwise. */ APR_DECLARE(apr_status_t) apr_file_eof(apr_file_t *fptr); /** * Open standard error as an apr file pointer. * @param thefile The apr file to use as stderr. * @param pool The pool to allocate the file out of. * * @remark The only reason that the apr_file_open_std* functions exist * is that you may not always have a stderr/out/in on Windows. This * is generally a problem with newer versions of Windows and services. * * @remark The other problem is that the C library functions generally work * differently on Windows and Unix. So, by using apr_file_open_std* * functions, you can get a handle to an APR struct that works with * the APR functions which are supposed to work identically on all * platforms. */ APR_DECLARE(apr_status_t) apr_file_open_stderr(apr_file_t **thefile, apr_pool_t *pool); /** * open standard output as an apr file pointer. * @param thefile The apr file to use as stdout. * @param pool The pool to allocate the file out of. * * @remark See remarks for apr_file_open_stdout. */ APR_DECLARE(apr_status_t) apr_file_open_stdout(apr_file_t **thefile, apr_pool_t *pool); /** * open standard input as an apr file pointer. * @param thefile The apr file to use as stdin. * @param pool The pool to allocate the file out of. * * @remark See remarks for apr_file_open_stdout. */ APR_DECLARE(apr_status_t) apr_file_open_stdin(apr_file_t **thefile, apr_pool_t *pool); /** * Read data from the specified file. * @param thefile The file descriptor to read from. * @param buf The buffer to store the data to. * @param nbytes On entry, the number of bytes to read; on exit, the number * of bytes read. * * @remark apr_file_read will read up to the specified number of * bytes, but never more. If there isn't enough data to fill that * number of bytes, all of the available data is read. The third * argument is modified to reflect the number of bytes read. If a * char was put back into the stream via ungetc, it will be the first * character returned. * * @remark It is not possible for both bytes to be read and an APR_EOF * or other error to be returned. APR_EINTR is never returned. */ APR_DECLARE(apr_status_t) apr_file_read(apr_file_t *thefile, void *buf, apr_size_t *nbytes); /** * Write data to the specified file. * @param thefile The file descriptor to write to. * @param buf The buffer which contains the data. * @param nbytes On entry, the number of bytes to write; on exit, the number * of bytes written. * * @remark apr_file_write will write up to the specified number of * bytes, but never more. If the OS cannot write that many bytes, it * will write as many as it can. The third argument is modified to * reflect the * number of bytes written. * * @remark It is possible for both bytes to be written and an error to * be returned. APR_EINTR is never returned. */ APR_DECLARE(apr_status_t) apr_file_write(apr_file_t *thefile, const void *buf, apr_size_t *nbytes); /** * Write data from iovec array to the specified file. * @param thefile The file descriptor to write to. * @param vec The array from which to get the data to write to the file. * @param nvec The number of elements in the struct iovec array. This must * be smaller than APR_MAX_IOVEC_SIZE. If it isn't, the function * will fail with APR_EINVAL. * @param nbytes The number of bytes written. * * @remark It is possible for both bytes to be written and an error to * be returned. APR_EINTR is never returned. * * @remark apr_file_writev is available even if the underlying * operating system doesn't provide writev(). */ APR_DECLARE(apr_status_t) apr_file_writev(apr_file_t *thefile, const struct iovec *vec, apr_size_t nvec, apr_size_t *nbytes); /** * Read data from the specified file, ensuring that the buffer is filled * before returning. * @param thefile The file descriptor to read from. * @param buf The buffer to store the data to. * @param nbytes The number of bytes to read. * @param bytes_read If non-NULL, this will contain the number of bytes read. * * @remark apr_file_read will read up to the specified number of * bytes, but never more. If there isn't enough data to fill that * number of bytes, then the process/thread will block until it is * available or EOF is reached. If a char was put back into the * stream via ungetc, it will be the first character returned. * * @remark It is possible for both bytes to be read and an error to be * returned. And if *bytes_read is less than nbytes, an accompanying * error is _always_ returned. * * @remark APR_EINTR is never returned. */ APR_DECLARE(apr_status_t) apr_file_read_full(apr_file_t *thefile, void *buf, apr_size_t nbytes, apr_size_t *bytes_read); /** * Write data to the specified file, ensuring that all of the data is * written before returning. * @param thefile The file descriptor to write to. * @param buf The buffer which contains the data. * @param nbytes The number of bytes to write. * @param bytes_written If non-NULL, set to the number of bytes written. * * @remark apr_file_write will write up to the specified number of * bytes, but never more. If the OS cannot write that many bytes, the * process/thread will block until they can be written. Exceptional * error such as "out of space" or "pipe closed" will terminate with * an error. * * @remark It is possible for both bytes to be written and an error to * be returned. And if *bytes_written is less than nbytes, an * accompanying error is _always_ returned. * * @remark APR_EINTR is never returned. */ APR_DECLARE(apr_status_t) apr_file_write_full(apr_file_t *thefile, const void *buf, apr_size_t nbytes, apr_size_t *bytes_written); /** * Write data from iovec array to the specified file, ensuring that all of the * data is written before returning. * @param thefile The file descriptor to write to. * @param vec The array from which to get the data to write to the file. * @param nvec The number of elements in the struct iovec array. This must * be smaller than APR_MAX_IOVEC_SIZE. If it isn't, the function * will fail with APR_EINVAL. * @param nbytes The number of bytes written. * * @remark apr_file_writev_full is available even if the underlying * operating system doesn't provide writev(). */ APR_DECLARE(apr_status_t) apr_file_writev_full(apr_file_t *thefile, const struct iovec *vec, apr_size_t nvec, apr_size_t *nbytes); /** * Write a character into the specified file. * @param ch The character to write. * @param thefile The file descriptor to write to */ APR_DECLARE(apr_status_t) apr_file_putc(char ch, apr_file_t *thefile); /** * Read a character from the specified file. * @param ch The character to read into * @param thefile The file descriptor to read from */ APR_DECLARE(apr_status_t) apr_file_getc(char *ch, apr_file_t *thefile); /** * Put a character back onto a specified stream. * @param ch The character to write. * @param thefile The file descriptor to write to */ APR_DECLARE(apr_status_t) apr_file_ungetc(char ch, apr_file_t *thefile); /** * Read a string from the specified file. * @param str The buffer to store the string in. * @param len The length of the string * @param thefile The file descriptor to read from * @remark The buffer will be NUL-terminated if any characters are stored. */ APR_DECLARE(apr_status_t) apr_file_gets(char *str, int len, apr_file_t *thefile); /** * Write the string into the specified file. * @param str The string to write. * @param thefile The file descriptor to write to */ APR_DECLARE(apr_status_t) apr_file_puts(const char *str, apr_file_t *thefile); /** * Flush the file's buffer. * @param thefile The file descriptor to flush */ APR_DECLARE(apr_status_t) apr_file_flush(apr_file_t *thefile); /** * Duplicate the specified file descriptor. * @param new_file The structure to duplicate into. * @param old_file The file to duplicate. * @param p The pool to use for the new file. * @remark *new_file must point to a valid apr_file_t, or point to NULL. */ APR_DECLARE(apr_status_t) apr_file_dup(apr_file_t **new_file, apr_file_t *old_file, apr_pool_t *p); /** * Duplicate the specified file descriptor and close the original * @param new_file The old file that is to be closed and reused * @param old_file The file to duplicate * @param p The pool to use for the new file * * @remark new_file MUST point at a valid apr_file_t. It cannot be NULL. */ APR_DECLARE(apr_status_t) apr_file_dup2(apr_file_t *new_file, apr_file_t *old_file, apr_pool_t *p); /** * Move the specified file descriptor to a new pool * @param new_file Pointer in which to return the new apr_file_t * @param old_file The file to move * @param p The pool to which the descriptor is to be moved * @remark Unlike apr_file_dup2(), this function doesn't do an * OS dup() operation on the underlying descriptor; it just * moves the descriptor's apr_file_t wrapper to a new pool. * @remark The new pool need not be an ancestor of old_file's pool. * @remark After calling this function, old_file may not be used */ APR_DECLARE(apr_status_t) apr_file_setaside(apr_file_t **new_file, apr_file_t *old_file, apr_pool_t *p); /** * Move the read/write file offset to a specified byte within a file. * @param thefile The file descriptor * @param where How to move the pointer, one of: * <PRE> * APR_SET -- set the offset to offset * APR_CUR -- add the offset to the current position * APR_END -- add the offset to the current file size * </PRE> * @param offset The offset to move the pointer to. * @remark The third argument is modified to be the offset the pointer was actually moved to. */ APR_DECLARE(apr_status_t) apr_file_seek(apr_file_t *thefile, apr_seek_where_t where, apr_off_t *offset); /** * Create an anonymous pipe. * @param in The file descriptor to use as input to the pipe. * @param out The file descriptor to use as output from the pipe. * @param pool The pool to operate on. * @remark By default, the returned file descriptors will be inherited * by child processes created using apr_proc_create(). This can be * changed using apr_file_inherit_unset(). */ APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in, apr_file_t **out, apr_pool_t *pool); /** * Create a named pipe. * @param filename The filename of the named pipe * @param perm The permissions for the newly created pipe. * @param pool The pool to operate on. */ APR_DECLARE(apr_status_t) apr_file_namedpipe_create(const char *filename, apr_fileperms_t perm, apr_pool_t *pool); /** * Get the timeout value for a pipe or manipulate the blocking state. * @param thepipe The pipe we are getting a timeout for. * @param timeout The current timeout value in microseconds. */ APR_DECLARE(apr_status_t) apr_file_pipe_timeout_get(apr_file_t *thepipe, apr_interval_time_t *timeout); /** * Set the timeout value for a pipe or manipulate the blocking state. * @param thepipe The pipe we are setting a timeout on. * @param timeout The timeout value in microseconds. Values < 0 mean wait * forever, 0 means do not wait at all. */ APR_DECLARE(apr_status_t) apr_file_pipe_timeout_set(apr_file_t *thepipe, apr_interval_time_t timeout); /** file (un)locking functions. */ /** * Establish a lock on the specified, open file. The lock may be advisory * or mandatory, at the discretion of the platform. The lock applies to * the file as a whole, rather than a specific range. Locks are established * on a per-thread/process basis; a second lock by the same thread will not * block. * @param thefile The file to lock. * @param type The type of lock to establish on the file. */ APR_DECLARE(apr_status_t) apr_file_lock(apr_file_t *thefile, int type); /** * Remove any outstanding locks on the file. * @param thefile The file to unlock. */ APR_DECLARE(apr_status_t) apr_file_unlock(apr_file_t *thefile); /**accessor and general file_io functions. */ /** * return the file name of the current file. * @param new_path The path of the file. * @param thefile The currently open file. */ APR_DECLARE(apr_status_t) apr_file_name_get(const char **new_path, apr_file_t *thefile); /** * Return the data associated with the current file. * @param data The user data associated with the file. * @param key The key to use for retreiving data associated with this file. * @param file The currently open file. */ APR_DECLARE(apr_status_t) apr_file_data_get(void **data, const char *key, apr_file_t *file); /** * Set the data associated with the current file. * @param file The currently open file. * @param data The user data to associate with the file. * @param key The key to use for assocaiteing data with the file. * @param cleanup The cleanup routine to use when the file is destroyed. */ APR_DECLARE(apr_status_t) apr_file_data_set(apr_file_t *file, void *data, const char *key, apr_status_t (*cleanup)(void *)); /** * Write a string to a file using a printf format. * @param fptr The file to write to. * @param format The format string * @param ... The values to substitute in the format string * @return The number of bytes written */ APR_DECLARE_NONSTD(int) apr_file_printf(apr_file_t *fptr, const char *format, ...) __attribute__((format(printf,2,3))); /** * set the specified file's permission bits. * @param fname The file (name) to apply the permissions to. * @param perms The permission bits to apply to the file. * * @warning Some platforms may not be able to apply all of the * available permission bits; APR_INCOMPLETE will be returned if some * permissions are specified which could not be set. * * @warning Platforms which do not implement this feature will return * APR_ENOTIMPL. */ APR_DECLARE(apr_status_t) apr_file_perms_set(const char *fname, apr_fileperms_t perms); /** * Set attributes of the specified file. * @param fname The full path to the file (using / on all systems) * @param attributes Or'd combination of * <PRE> * APR_FILE_ATTR_READONLY - make the file readonly * APR_FILE_ATTR_EXECUTABLE - make the file executable * APR_FILE_ATTR_HIDDEN - make the file hidden * </PRE> * @param attr_mask Mask of valid bits in attributes. * @param pool the pool to use. * @remark This function should be used in preference to explict manipulation * of the file permissions, because the operations to provide these * attributes are platform specific and may involve more than simply * setting permission bits. * @warning Platforms which do not implement this feature will return * APR_ENOTIMPL. */ APR_DECLARE(apr_status_t) apr_file_attrs_set(const char *fname, apr_fileattrs_t attributes, apr_fileattrs_t attr_mask, apr_pool_t *pool); /** * Set the mtime of the specified file. * @param fname The full path to the file (using / on all systems) * @param mtime The mtime to apply to the file. * @param pool The pool to use. * @warning Platforms which do not implement this feature will return * APR_ENOTIMPL. */ APR_DECLARE(apr_status_t) apr_file_mtime_set(const char *fname, apr_time_t mtime, apr_pool_t *pool); /** * Create a new directory on the file system. * @param path the path for the directory to be created. (use / on all systems) * @param perm Permissions for the new direcoty. * @param pool the pool to use. */ APR_DECLARE(apr_status_t) apr_dir_make(const char *path, apr_fileperms_t perm, apr_pool_t *pool); /** Creates a new directory on the file system, but behaves like * 'mkdir -p'. Creates intermediate directories as required. No error * will be reported if PATH already exists. * @param path the path for the directory to be created. (use / on all systems) * @param perm Permissions for the new direcoty. * @param pool the pool to use. */ APR_DECLARE(apr_status_t) apr_dir_make_recursive(const char *path, apr_fileperms_t perm, apr_pool_t *pool); /** * Remove directory from the file system. * @param path the path for the directory to be removed. (use / on all systems) * @param pool the pool to use. */ APR_DECLARE(apr_status_t) apr_dir_remove(const char *path, apr_pool_t *pool); /** * get the specified file's stats. * @param finfo Where to store the information about the file. * @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_ values * @param thefile The file to get information about. */ APR_DECLARE(apr_status_t) apr_file_info_get(apr_finfo_t *finfo, apr_int32_t wanted, apr_file_t *thefile); /** * Truncate the file's length to the specified offset * @param fp The file to truncate * @param offset The offset to truncate to. */ APR_DECLARE(apr_status_t) apr_file_trunc(apr_file_t *fp, apr_off_t offset); /** * Retrieve the flags that were passed into apr_file_open() * when the file was opened. * @return apr_int32_t the flags */ APR_DECLARE(apr_int32_t) apr_file_flags_get(apr_file_t *f); /** * Get the pool used by the file. */ APR_POOL_DECLARE_ACCESSOR(file); /** * Set a file to be inherited by child processes. * */ APR_DECLARE_INHERIT_SET(file); /** * Unset a file from being inherited by child processes. */ APR_DECLARE_INHERIT_UNSET(file); /** * Open a temporary file * @param fp The apr file to use as a temporary file. * @param templ The template to use when creating a temp file. * @param flags The flags to open the file with. If this is zero, * the file is opened with * APR_CREATE | APR_READ | APR_WRITE | APR_EXCL | APR_DELONCLOSE * @param p The pool to allocate the file out of. * @remark * This function generates a unique temporary file name from template. * The last six characters of template must be XXXXXX and these are replaced * with a string that makes the filename unique. Since it will be modified, * template must not be a string constant, but should be declared as a character * array. * */ APR_DECLARE(apr_status_t) apr_file_mktemp(apr_file_t **fp, char *templ, apr_int32_t flags, apr_pool_t *p); /** * Find an existing directory suitable as a temporary storage location. * @param temp_dir The temp directory. * @param p The pool to use for any necessary allocations. * @remark * This function uses an algorithm to search for a directory that an * an application can use for temporary storage. Once such a * directory is found, that location is cached by the library. Thus, * callers only pay the cost of this algorithm once if that one time * is successful. * */ APR_DECLARE(apr_status_t) apr_temp_dir_get(const char **temp_dir, apr_pool_t *p); /** @} */ #ifdef __cplusplus } #endif #endif /* ! APR_FILE_IO_H */
001-log4cxx
trunk/src/apr/include/apr_file_io.h
C
asf20
33,929
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef APR_THREAD_COND_H #define APR_THREAD_COND_H /** * @file apr_thread_cond.h * @brief APR Condition Variable Routines */ #include "apr.h" #include "apr_pools.h" #include "apr_errno.h" #include "apr_time.h" #include "apr_thread_mutex.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ #if APR_HAS_THREADS || defined(DOXYGEN) /** * @defgroup apr_thread_cond Condition Variable Routines * @ingroup APR * @{ */ /** Opaque structure for thread condition variables */ typedef struct apr_thread_cond_t apr_thread_cond_t; /** * Note: destroying a condition variable (or likewise, destroying or * clearing the pool from which a condition variable was allocated) if * any threads are blocked waiting on it gives undefined results. */ /** * Create and initialize a condition variable that can be used to signal * and schedule threads in a single process. * @param cond the memory address where the newly created condition variable * will be stored. * @param pool the pool from which to allocate the mutex. */ APR_DECLARE(apr_status_t) apr_thread_cond_create(apr_thread_cond_t **cond, apr_pool_t *pool); /** * Put the active calling thread to sleep until signaled to wake up. Each * condition variable must be associated with a mutex, and that mutex must * be locked before calling this function, or the behavior will be * undefined. As the calling thread is put to sleep, the given mutex * will be simultaneously released; and as this thread wakes up the lock * is again simultaneously acquired. * @param cond the condition variable on which to block. * @param mutex the mutex that must be locked upon entering this function, * is released while the thread is asleep, and is again acquired before * returning from this function. */ APR_DECLARE(apr_status_t) apr_thread_cond_wait(apr_thread_cond_t *cond, apr_thread_mutex_t *mutex); /** * Put the active calling thread to sleep until signaled to wake up or * the timeout is reached. Each condition variable must be associated * with a mutex, and that mutex must be locked before calling this * function, or the behavior will be undefined. As the calling thread * is put to sleep, the given mutex will be simultaneously released; * and as this thread wakes up the lock is again simultaneously acquired. * @param cond the condition variable on which to block. * @param mutex the mutex that must be locked upon entering this function, * is released while the thread is asleep, and is again acquired before * returning from this function. * @param timeout The amount of time in microseconds to wait. This is * a maximum, not a minimum. If the condition is signaled, we * will wake up before this time, otherwise the error APR_TIMEUP * is returned. */ APR_DECLARE(apr_status_t) apr_thread_cond_timedwait(apr_thread_cond_t *cond, apr_thread_mutex_t *mutex, apr_interval_time_t timeout); /** * Signals a single thread, if one exists, that is blocking on the given * condition variable. That thread is then scheduled to wake up and acquire * the associated mutex. Although it is not required, if predictable scheduling * is desired, that mutex must be locked while calling this function. * @param cond the condition variable on which to produce the signal. */ APR_DECLARE(apr_status_t) apr_thread_cond_signal(apr_thread_cond_t *cond); /** * Signals all threads blocking on the given condition variable. * Each thread that was signaled is then scheduled to wake up and acquire * the associated mutex. This will happen in a serialized manner. * @param cond the condition variable on which to produce the broadcast. */ APR_DECLARE(apr_status_t) apr_thread_cond_broadcast(apr_thread_cond_t *cond); /** * Destroy the condition variable and free the associated memory. * @param cond the condition variable to destroy. */ APR_DECLARE(apr_status_t) apr_thread_cond_destroy(apr_thread_cond_t *cond); /** * Get the pool used by this thread_cond. * @return apr_pool_t the pool */ APR_POOL_DECLARE_ACCESSOR(thread_cond); #endif /* APR_HAS_THREADS */ /** @} */ #ifdef __cplusplus } #endif #endif /* ! APR_THREAD_COND_H */
001-log4cxx
trunk/src/apr/include/apr_thread_cond.h
C
asf20
5,192
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "apr.h" /* configuration data */ /** * @file apr_want.h * @brief APR Standard Headers Support * * <PRE> * Features: * * APR_WANT_STRFUNC: strcmp, strcat, strcpy, etc * APR_WANT_MEMFUNC: memcmp, memcpy, etc * APR_WANT_STDIO: <stdio.h> and related bits * APR_WANT_IOVEC: struct iovec * APR_WANT_BYTEFUNC: htons, htonl, ntohl, ntohs * * Typical usage: * * #define APR_WANT_STRFUNC * #define APR_WANT_MEMFUNC * #include "apr_want.h" * * The appropriate headers will be included. * * Note: it is safe to use this in a header (it won't interfere with other * headers' or source files' use of apr_want.h) * </PRE> */ /* --------------------------------------------------------------------- */ #ifdef APR_WANT_STRFUNC #if APR_HAVE_STRING_H #include <string.h> #endif #if APR_HAVE_STRINGS_H #include <strings.h> #endif #undef APR_WANT_STRFUNC #endif /* --------------------------------------------------------------------- */ #ifdef APR_WANT_MEMFUNC #if APR_HAVE_STRING_H #include <string.h> #endif #undef APR_WANT_MEMFUNC #endif /* --------------------------------------------------------------------- */ #ifdef APR_WANT_STDIO #if APR_HAVE_STDIO_H #include <stdio.h> #endif #undef APR_WANT_STDIO #endif /* --------------------------------------------------------------------- */ #ifdef APR_WANT_IOVEC #if APR_HAVE_SYS_UIO_H #include <sys/uio.h> #endif #undef APR_WANT_IOVEC #endif /* --------------------------------------------------------------------- */ #ifdef APR_WANT_BYTEFUNC /* Single Unix says they are in arpa/inet.h. Linux has them in * netinet/in.h. FreeBSD has them in arpa/inet.h but requires that * netinet/in.h be included first. */ #if APR_HAVE_NETINET_IN_H #include <netinet/in.h> #endif #if APR_HAVE_ARPA_INET_H #include <arpa/inet.h> #endif #undef APR_WANT_BYTEFUNC #endif /* --------------------------------------------------------------------- */
001-log4cxx
trunk/src/apr/include/apr_want.h
C
asf20
2,756
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef APR_SHM_H #define APR_SHM_H /** * @file apr_shm.h * @brief APR Shared Memory Routines */ #include "apr.h" #include "apr_pools.h" #include "apr_errno.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /** * @defgroup apr_shm Shared Memory Routines * @ingroup APR * @{ */ /** * Private, platform-specific data struture representing a shared memory * segment. */ typedef struct apr_shm_t apr_shm_t; /** * Create and make accessable a shared memory segment. * @param m The shared memory structure to create. * @param reqsize The desired size of the segment. * @param filename The file to use for shared memory on platforms that * require it. * @param pool the pool from which to allocate the shared memory * structure. * @remark A note about Anonymous vs. Named shared memory segments: * Not all plaforms support anonymous shared memory segments, but in * some cases it is prefered over other types of shared memory * implementations. Passing a NULL 'file' parameter to this function * will cause the subsystem to use anonymous shared memory segments. * If such a system is not available, APR_ENOTIMPL is returned. * @remark A note about allocation sizes: * On some platforms it is necessary to store some metainformation * about the segment within the actual segment. In order to supply * the caller with the requested size it may be necessary for the * implementation to request a slightly greater segment length * from the subsystem. In all cases, the apr_shm_baseaddr_get() * function will return the first usable byte of memory. * */ APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m, apr_size_t reqsize, const char *filename, apr_pool_t *pool); /** * Remove shared memory segment associated with a filename. * @param filename The filename associated with shared-memory segment which * needs to be removed * @param pool The pool used for file operations * @remark This function is only supported on platforms which support * name-based shared memory segments, and will return APR_ENOTIMPL on * platforms without such support. */ APR_DECLARE(apr_status_t) apr_shm_remove(const char *filename, apr_pool_t *pool); /** * Destroy a shared memory segment and associated memory. * @param m The shared memory segment structure to destroy. */ APR_DECLARE(apr_status_t) apr_shm_destroy(apr_shm_t *m); /** * Attach to a shared memory segment that was created * by another process. * @param m The shared memory structure to create. * @param filename The file used to create the original segment. * (This MUST match the original filename.) * @param pool the pool from which to allocate the shared memory * structure for this process. */ APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m, const char *filename, apr_pool_t *pool); /** * Detach from a shared memory segment without destroying it. * @param m The shared memory structure representing the segment * to detach from. */ APR_DECLARE(apr_status_t) apr_shm_detach(apr_shm_t *m); /** * Retrieve the base address of the shared memory segment. * NOTE: This address is only usable within the callers address * space, since this API does not guarantee that other attaching * processes will maintain the same address mapping. * @param m The shared memory segment from which to retrieve * the base address. * @return address, aligned by APR_ALIGN_DEFAULT. */ APR_DECLARE(void *) apr_shm_baseaddr_get(const apr_shm_t *m); /** * Retrieve the length of a shared memory segment in bytes. * @param m The shared memory segment from which to retrieve * the segment length. */ APR_DECLARE(apr_size_t) apr_shm_size_get(const apr_shm_t *m); /** * Get the pool used by this shared memory segment. */ APR_POOL_DECLARE_ACCESSOR(shm); /** @} */ #ifdef __cplusplus } #endif #endif /* APR_SHM_T */
001-log4cxx
trunk/src/apr/include/apr_shm.h
C
asf20
5,025
/* * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)fnmatch.h 8.1 (Berkeley) 6/2/93 */ /* This file has been modified by the Apache Software Foundation. */ #ifndef _APR_FNMATCH_H_ #define _APR_FNMATCH_H_ /** * @file apr_fnmatch.h * @brief APR FNMatch Functions */ #include "apr_errno.h" #include "apr_tables.h" #ifdef __cplusplus extern "C" { #endif /** * @defgroup apr_fnmatch Filename Matching Functions * @ingroup APR * @{ */ #define APR_FNM_NOMATCH 1 /**< Match failed. */ #define APR_FNM_NOESCAPE 0x01 /**< Disable backslash escaping. */ #define APR_FNM_PATHNAME 0x02 /**< Slash must be matched by slash. */ #define APR_FNM_PERIOD 0x04 /**< Period must be matched by period. */ #define APR_FNM_CASE_BLIND 0x08 /**< Compare characters case-insensitively. * @remark This flag is an Apache addition */ /** * Try to match the string to the given pattern, return APR_SUCCESS if * match, else return APR_FNM_NOMATCH. * @param pattern The pattern to match to * @param strings The string we are trying to match * @param flags flags to use in the match. Bitwise OR of: * <PRE> * APR_FNM_NOESCAPE Disable backslash escaping * APR_FNM_PATHNAME Slash must be matched by slash * APR_FNM_PERIOD Period must be matched by period * APR_FNM_CASE_BLIND Compare characters case-insensitively. * </PRE> */ APR_DECLARE(apr_status_t) apr_fnmatch(const char *pattern, const char *strings, int flags); /** * Determine if the given pattern is a regular expression. * @param pattern The pattern to search for glob characters. * @return non-zero if pattern has any glob characters in it */ APR_DECLARE(int) apr_fnmatch_test(const char *pattern); /** * Find all files that match a specified pattern. * @param pattern The pattern to use for finding files. * @param result Array to use when storing the results * @param p The pool to use. * @return non-zero if pattern has any glob characters in it */ APR_DECLARE(apr_status_t) apr_match_glob(const char *pattern, apr_array_header_t **result, apr_pool_t *p); /** @} */ #ifdef __cplusplus } #endif #endif /* !_APR_FNMATCH_H_ */
001-log4cxx
trunk/src/apr/include/apr_fnmatch.h
C
asf20
4,180
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef APR_ATOMIC_H #define APR_ATOMIC_H /** * @file apr_atomic.h * @brief APR Atomic Operations */ #include "apr.h" #include "apr_pools.h" #ifdef __cplusplus extern "C" { #endif /** * @defgroup apr_atomic Atomic Operations * @ingroup APR * @{ */ /** * this function is required on some platforms to initialize the * atomic operation's internal structures * @param p pool * @return APR_SUCCESS on successful completion */ APR_DECLARE(apr_status_t) apr_atomic_init(apr_pool_t *p); /* * Atomic operations on 32-bit values * Note: Each of these functions internally implements a memory barrier * on platforms that require it */ /** * atomically read an apr_uint32_t from memory * @param mem the pointer */ APR_DECLARE(apr_uint32_t) apr_atomic_read32(volatile apr_uint32_t *mem); /** * atomically set an apr_uint32_t in memory * @param mem pointer to the object * @param val value that the object will assume */ APR_DECLARE(void) apr_atomic_set32(volatile apr_uint32_t *mem, apr_uint32_t val); /** * atomically add 'val' to an apr_uint32_t * @param mem pointer to the object * @param val amount to add * @return old value pointed to by mem */ APR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val); /** * atomically subtract 'val' from an apr_uint32_t * @param mem pointer to the object * @param val amount to subtract */ APR_DECLARE(void) apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val); /** * atomically increment an apr_uint32_t by 1 * @param mem pointer to the object * @return old value pointed to by mem */ APR_DECLARE(apr_uint32_t) apr_atomic_inc32(volatile apr_uint32_t *mem); /** * atomically decrement an apr_uint32_t by 1 * @param mem pointer to the atomic value * @return zero if the value becomes zero on decrement, otherwise non-zero */ APR_DECLARE(int) apr_atomic_dec32(volatile apr_uint32_t *mem); /** * compare an apr_uint32_t's value with 'cmp'. * If they are the same swap the value with 'with' * @param mem pointer to the value * @param with what to swap it with * @param cmp the value to compare it to * @return the old value of *mem */ APR_DECLARE(apr_uint32_t) apr_atomic_cas32(volatile apr_uint32_t *mem, apr_uint32_t with, apr_uint32_t cmp); /** * exchange an apr_uint32_t's value with 'val'. * @param mem pointer to the value * @param val what to swap it with * @return the old value of *mem */ APR_DECLARE(apr_uint32_t) apr_atomic_xchg32(volatile apr_uint32_t *mem, apr_uint32_t val); /** * compare the pointer's value with cmp. * If they are the same swap the value with 'with' * @param mem pointer to the pointer * @param with what to swap it with * @param cmp the value to compare it to * @return the old value of the pointer */ APR_DECLARE(void*) apr_atomic_casptr(volatile void **mem, void *with, const void *cmp); /** @} */ #ifdef __cplusplus } #endif #endif /* !APR_ATOMIC_H */
001-log4cxx
trunk/src/apr/include/apr_atomic.h
C
asf20
3,766
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef APR_HASH_H #define APR_HASH_H /** * @file apr_hash.h * @brief APR Hash Tables */ #include "apr_pools.h" #ifdef __cplusplus extern "C" { #endif /** * @defgroup apr_hash Hash Tables * @ingroup APR * @{ */ /** * When passing a key to apr_hash_set or apr_hash_get, this value can be * passed to indicate a string-valued key, and have apr_hash compute the * length automatically. * * @remark apr_hash will use strlen(key) for the length. The NUL terminator * is not included in the hash value (why throw a constant in?). * Since the hash table merely references the provided key (rather * than copying it), apr_hash_this() will return the NUL-term'd key. */ #define APR_HASH_KEY_STRING (-1) /** * Abstract type for hash tables. */ typedef struct apr_hash_t apr_hash_t; /** * Abstract type for scanning hash tables. */ typedef struct apr_hash_index_t apr_hash_index_t; /** * Callback functions for calculating hash values. * @param key The key. * @param klen The length of the key, or APR_HASH_KEY_STRING to use the string * length. If APR_HASH_KEY_STRING then returns the actual key length. */ typedef unsigned int (*apr_hashfunc_t)(const char *key, apr_ssize_t *klen); /** * The default hash function. */ APR_DECLARE_NONSTD(unsigned int) apr_hashfunc_default(const char *key, apr_ssize_t *klen); /** * Create a hash table. * @param pool The pool to allocate the hash table out of * @return The hash table just created */ APR_DECLARE(apr_hash_t *) apr_hash_make(apr_pool_t *pool); /** * Create a hash table with a custom hash function * @param pool The pool to allocate the hash table out of * @param hash_func A custom hash function. * @return The hash table just created */ APR_DECLARE(apr_hash_t *) apr_hash_make_custom(apr_pool_t *pool, apr_hashfunc_t hash_func); /** * Make a copy of a hash table * @param pool The pool from which to allocate the new hash table * @param h The hash table to clone * @return The hash table just created * @remark Makes a shallow copy */ APR_DECLARE(apr_hash_t *) apr_hash_copy(apr_pool_t *pool, const apr_hash_t *h); /** * Associate a value with a key in a hash table. * @param ht The hash table * @param key Pointer to the key * @param klen Length of the key. Can be APR_HASH_KEY_STRING to use the string length. * @param val Value to associate with the key * @remark If the value is NULL the hash entry is deleted. */ APR_DECLARE(void) apr_hash_set(apr_hash_t *ht, const void *key, apr_ssize_t klen, const void *val); /** * Look up the value associated with a key in a hash table. * @param ht The hash table * @param key Pointer to the key * @param klen Length of the key. Can be APR_HASH_KEY_STRING to use the string length. * @return Returns NULL if the key is not present. */ APR_DECLARE(void *) apr_hash_get(apr_hash_t *ht, const void *key, apr_ssize_t klen); /** * Start iterating over the entries in a hash table. * @param p The pool to allocate the apr_hash_index_t iterator. If this * pool is NULL, then an internal, non-thread-safe iterator is used. * @param ht The hash table * @remark There is no restriction on adding or deleting hash entries during * an iteration (although the results may be unpredictable unless all you do * is delete the current entry) and multiple iterations can be in * progress at the same time. * @example */ /** * <PRE> * * int sum_values(apr_pool_t *p, apr_hash_t *ht) * { * apr_hash_index_t *hi; * void *val; * int sum = 0; * for (hi = apr_hash_first(p, ht); hi; hi = apr_hash_next(hi)) { * apr_hash_this(hi, NULL, NULL, &val); * sum += *(int *)val; * } * return sum; * } * </PRE> */ APR_DECLARE(apr_hash_index_t *) apr_hash_first(apr_pool_t *p, apr_hash_t *ht); /** * Continue iterating over the entries in a hash table. * @param hi The iteration state * @return a pointer to the updated iteration state. NULL if there are no more * entries. */ APR_DECLARE(apr_hash_index_t *) apr_hash_next(apr_hash_index_t *hi); /** * Get the current entry's details from the iteration state. * @param hi The iteration state * @param key Return pointer for the pointer to the key. * @param klen Return pointer for the key length. * @param val Return pointer for the associated value. * @remark The return pointers should point to a variable that will be set to the * corresponding data, or they may be NULL if the data isn't interesting. */ APR_DECLARE(void) apr_hash_this(apr_hash_index_t *hi, const void **key, apr_ssize_t *klen, void **val); /** * Get the number of key/value pairs in the hash table. * @param ht The hash table * @return The number of key/value pairs in the hash table. */ APR_DECLARE(unsigned int) apr_hash_count(apr_hash_t *ht); /** * Merge two hash tables into one new hash table. The values of the overlay * hash override the values of the base if both have the same key. Both * hash tables must use the same hash function. * @param p The pool to use for the new hash table * @param overlay The table to add to the initial table * @param base The table that represents the initial values of the new table * @return A new hash table containing all of the data from the two passed in */ APR_DECLARE(apr_hash_t *) apr_hash_overlay(apr_pool_t *p, const apr_hash_t *overlay, const apr_hash_t *base); /** * Merge two hash tables into one new hash table. If the same key * is present in both tables, call the supplied merge function to * produce a merged value for the key in the new table. Both * hash tables must use the same hash function. * @param p The pool to use for the new hash table * @param h1 The first of the tables to merge * @param h2 The second of the tables to merge * @param merger A callback function to merge values, or NULL to * make values from h1 override values from h2 (same semantics as * apr_hash_overlay()) * @param data Client data to pass to the merger function * @return A new hash table containing all of the data from the two passed in */ APR_DECLARE(apr_hash_t *) apr_hash_merge(apr_pool_t *p, const apr_hash_t *h1, const apr_hash_t *h2, void * (*merger)(apr_pool_t *p, const void *key, apr_ssize_t klen, const void *h1_val, const void *h2_val, const void *data), const void *data); /** * Get a pointer to the pool which the hash table was created in */ APR_POOL_DECLARE_ACCESSOR(hash); /** @} */ #ifdef __cplusplus } #endif #endif /* !APR_HASH_H */
001-log4cxx
trunk/src/apr/include/apr_hash.h
C
asf20
8,087
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef APR_GENERAL_H #define APR_GENERAL_H /** * @file apr_general.h * This is collection of oddballs that didn't fit anywhere else, * and might move to more appropriate headers with the release * of APR 1.0. * @brief APR Miscellaneous library routines */ #include "apr.h" #include "apr_pools.h" #include "apr_errno.h" #if APR_HAVE_SIGNAL_H #include <signal.h> #endif #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /** * @defgroup apr_general Miscellaneous library routines * @ingroup APR * This is collection of oddballs that didn't fit anywhere else, * and might move to more appropriate headers with the release * of APR 1.0. * @{ */ /** FALSE */ #ifndef FALSE #define FALSE 0 #endif /** TRUE */ #ifndef TRUE #define TRUE (!FALSE) #endif /** a space */ #define APR_ASCII_BLANK '\040' /** a carrige return */ #define APR_ASCII_CR '\015' /** a line feed */ #define APR_ASCII_LF '\012' /** a tab */ #define APR_ASCII_TAB '\011' /** signal numbers typedef */ typedef int apr_signum_t; /** * Finding offsets of elements within structures. * Taken from the X code... they've sweated portability of this stuff * so we don't have to. Sigh... * @param p_type pointer type name * @param field data field within the structure pointed to * @return offset */ #if defined(CRAY) || (defined(__arm) && !defined(LINUX)) #ifdef __STDC__ #define APR_OFFSET(p_type,field) _Offsetof(p_type,field) #else #ifdef CRAY2 #define APR_OFFSET(p_type,field) \ (sizeof(int)*((unsigned int)&(((p_type)NULL)->field))) #else /* !CRAY2 */ #define APR_OFFSET(p_type,field) ((unsigned int)&(((p_type)NULL)->field)) #endif /* !CRAY2 */ #endif /* __STDC__ */ #else /* ! (CRAY || __arm) */ #define APR_OFFSET(p_type,field) \ ((long) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL))) #endif /* !CRAY */ /** * Finding offsets of elements within structures. * @param s_type structure type name * @param field data field within the structure * @return offset */ #if defined(offsetof) && !defined(__cplusplus) #define APR_OFFSETOF(s_type,field) offsetof(s_type,field) #else #define APR_OFFSETOF(s_type,field) APR_OFFSET(s_type*,field) #endif #ifndef DOXYGEN /* A couple of prototypes for functions in case some platform doesn't * have it */ #if (!APR_HAVE_STRCASECMP) && (APR_HAVE_STRICMP) #define strcasecmp(s1, s2) stricmp(s1, s2) #elif (!APR_HAVE_STRCASECMP) int strcasecmp(const char *a, const char *b); #endif #if (!APR_HAVE_STRNCASECMP) && (APR_HAVE_STRNICMP) #define strncasecmp(s1, s2, n) strnicmp(s1, s2, n) #elif (!APR_HAVE_STRNCASECMP) int strncasecmp(const char *a, const char *b, size_t n); #endif #endif /** * Alignment macros */ /* APR_ALIGN() is only to be used to align on a power of 2 boundary */ #define APR_ALIGN(size, boundary) \ (((size) + ((boundary) - 1)) & ~((boundary) - 1)) /** Default alignment */ #define APR_ALIGN_DEFAULT(size) APR_ALIGN(size, 8) /** * String and memory functions */ /* APR_STRINGIFY is defined here, and also in apr_release.h, so wrap it */ #ifndef APR_STRINGIFY /** Properly quote a value as a string in the C preprocessor */ #define APR_STRINGIFY(n) APR_STRINGIFY_HELPER(n) /** Helper macro for APR_STRINGIFY */ #define APR_STRINGIFY_HELPER(n) #n #endif #if (!APR_HAVE_MEMMOVE) #define memmove(a,b,c) bcopy(b,a,c) #endif #if (!APR_HAVE_MEMCHR) void *memchr(const void *s, int c, size_t n); #endif /** @} */ /** * @defgroup apr_library Library initialization and termination * @{ */ /** * Setup any APR internal data structures. This MUST be the first function * called for any APR library. * @remark See apr_app_initialize if this is an application, rather than * a library consumer of apr. */ APR_DECLARE(apr_status_t) apr_initialize(void); /** * Set up an application with normalized argc, argv (and optionally env) in * order to deal with platform-specific oddities, such as Win32 services, * code pages and signals. This must be the first function called for any * APR program. * @param argc Pointer to the argc that may be corrected * @param argv Pointer to the argv that may be corrected * @param env Pointer to the env that may be corrected, may be NULL * @remark See apr_initialize if this is a library consumer of apr. * Otherwise, this call is identical to apr_initialize, and must be closed * with a call to apr_terminate at the end of program execution. */ APR_DECLARE(apr_status_t) apr_app_initialize(int *argc, char const * const * *argv, char const * const * *env); /** * Tear down any APR internal data structures which aren't torn down * automatically. * @remark An APR program must call this function at termination once it * has stopped using APR services. The APR developers suggest using * atexit to ensure this is called. When using APR from a language * other than C that has problems with the calling convention, use * apr_terminate2() instead. */ APR_DECLARE_NONSTD(void) apr_terminate(void); /** * Tear down any APR internal data structures which aren't torn down * automatically, same as apr_terminate * @remark An APR program must call either the apr_terminate or apr_terminate2 * function once it it has finished using APR services. The APR * developers suggest using atexit(apr_terminate) to ensure this is done. * apr_terminate2 exists to allow non-c language apps to tear down apr, * while apr_terminate is recommended from c language applications. */ APR_DECLARE(void) apr_terminate2(void); /** @} */ /** * @defgroup apr_random Random Functions * @{ */ #if APR_HAS_RANDOM || defined(DOXYGEN) /* TODO: I'm not sure this is the best place to put this prototype...*/ /** * Generate random bytes. * @param buf Buffer to fill with random bytes * @param length Length of buffer in bytes */ APR_DECLARE(apr_status_t) apr_generate_random_bytes(unsigned char * buf, apr_size_t length); #endif /** @} */ #ifdef __cplusplus } #endif #endif /* ! APR_GENERAL_H */
001-log4cxx
trunk/src/apr/include/apr_general.h
C
asf20
7,000
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef APR_THREAD_PROC_H #define APR_THREAD_PROC_H /** * @file apr_thread_proc.h * @brief APR Thread and Process Library */ #include "apr.h" #include "apr_file_io.h" #include "apr_pools.h" #include "apr_errno.h" #if APR_HAVE_STRUCT_RLIMIT #include <sys/time.h> #include <sys/resource.h> #endif #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /** * @defgroup apr_thread_proc Threads and Process Functions * @ingroup APR * @{ */ typedef enum { APR_SHELLCMD, /**< use the shell to invoke the program */ APR_PROGRAM, /**< invoke the program directly, no copied env */ APR_PROGRAM_ENV, /**< invoke the program, replicating our environment */ APR_PROGRAM_PATH, /**< find program on PATH, use our environment */ APR_SHELLCMD_ENV /**< use the shell to invoke the program, * replicating our environment */ } apr_cmdtype_e; typedef enum { APR_WAIT, /**< wait for the specified process to finish */ APR_NOWAIT /**< do not wait -- just see if it has finished */ } apr_wait_how_e; /* I am specifically calling out the values so that the macros below make * more sense. Yes, I know I don't need to, but I am hoping this makes what * I am doing more clear. If you want to add more reasons to exit, continue * to use bitmasks. */ typedef enum { APR_PROC_EXIT = 1, /**< process exited normally */ APR_PROC_SIGNAL = 2, /**< process exited due to a signal */ APR_PROC_SIGNAL_CORE = 4 /**< process exited and dumped a core file */ } apr_exit_why_e; /** did we exit the process */ #define APR_PROC_CHECK_EXIT(x) (x & APR_PROC_EXIT) /** did we get a signal */ #define APR_PROC_CHECK_SIGNALED(x) (x & APR_PROC_SIGNAL) /** did we get core */ #define APR_PROC_CHECK_CORE_DUMP(x) (x & APR_PROC_SIGNAL_CORE) /** @see apr_procattr_io_set */ #define APR_NO_PIPE 0 /** @see apr_procattr_io_set */ #define APR_FULL_BLOCK 1 /** @see apr_procattr_io_set */ #define APR_FULL_NONBLOCK 2 /** @see apr_procattr_io_set */ #define APR_PARENT_BLOCK 3 /** @see apr_procattr_io_set */ #define APR_CHILD_BLOCK 4 /** @see apr_procattr_limit_set */ #define APR_LIMIT_CPU 0 /** @see apr_procattr_limit_set */ #define APR_LIMIT_MEM 1 /** @see apr_procattr_limit_set */ #define APR_LIMIT_NPROC 2 /** @see apr_procattr_limit_set */ #define APR_LIMIT_NOFILE 3 /** * @defgroup APR_OC Other Child Flags * @{ */ #define APR_OC_REASON_DEATH 0 /**< child has died, caller must call * unregister still */ #define APR_OC_REASON_UNWRITABLE 1 /**< write_fd is unwritable */ #define APR_OC_REASON_RESTART 2 /**< a restart is occuring, perform * any necessary cleanup (including * sending a special signal to child) */ #define APR_OC_REASON_UNREGISTER 3 /**< unregister has been called, do * whatever is necessary (including * kill the child) */ #define APR_OC_REASON_LOST 4 /**< somehow the child exited without * us knowing ... buggy os? */ #define APR_OC_REASON_RUNNING 5 /**< a health check is occuring, * for most maintainence functions * this is a no-op. */ /** @} */ /** The APR process type */ typedef struct apr_proc_t { /** The process ID */ pid_t pid; /** Parent's side of pipe to child's stdin */ apr_file_t *in; /** Parent's side of pipe to child's stdout */ apr_file_t *out; /** Parent's side of pipe to child's stdouterr */ apr_file_t *err; #if APR_HAS_PROC_INVOKED || defined(DOXYGEN) /** Diagnositics/debugging string of the command invoked for * this process [only present if APR_HAS_PROC_INVOKED is true] * @remark Only enabled on Win32 by default. * @bug This should either always or never be present in release * builds - since it breaks binary compatibility. We may enable * it always in APR 1.0 yet leave it undefined in most cases. */ char *invoked; #endif #if defined(WIN32) || defined(DOXYGEN) /** (Win32 only) Creator's handle granting access to the process * @remark This handle is closed and reset to NULL in every case * corresponding to a waitpid() on Unix which returns the exit status. * Therefore Win32 correspond's to Unix's zombie reaping characteristics * and avoids potential handle leaks. */ HANDLE hproc; #endif } apr_proc_t; /** * The prototype for APR child errfn functions. (See the description * of apr_procattr_child_errfn_set() for more information.) * It is passed the following parameters: * @param pool Pool associated with the apr_proc_t. If your child * error function needs user data, associate it with this * pool. * @param err APR error code describing the error * @param description Text description of type of processing which failed */ typedef void (apr_child_errfn_t)(apr_pool_t *proc, apr_status_t err, const char *description); /** Opaque Thread structure. */ typedef struct apr_thread_t apr_thread_t; /** Opaque Thread attributes structure. */ typedef struct apr_threadattr_t apr_threadattr_t; /** Opaque Process attributes structure. */ typedef struct apr_procattr_t apr_procattr_t; /** Opaque control variable for one-time atomic variables. */ typedef struct apr_thread_once_t apr_thread_once_t; /** Opaque thread private address space. */ typedef struct apr_threadkey_t apr_threadkey_t; /** Opaque record of child process. */ typedef struct apr_other_child_rec_t apr_other_child_rec_t; /** * The prototype for any APR thread worker functions. */ typedef void *(APR_THREAD_FUNC *apr_thread_start_t)(apr_thread_t*, void*); typedef enum { APR_KILL_NEVER, /**< process is never sent any signals */ APR_KILL_ALWAYS, /**< process is sent SIGKILL on apr_pool_t cleanup */ APR_KILL_AFTER_TIMEOUT, /**< SIGTERM, wait 3 seconds, SIGKILL */ APR_JUST_WAIT, /**< wait forever for the process to complete */ APR_KILL_ONLY_ONCE /**< send SIGTERM and then wait */ } apr_kill_conditions_e; /* Thread Function definitions */ #if APR_HAS_THREADS /** * Create and initialize a new threadattr variable * @param new_attr The newly created threadattr. * @param cont The pool to use */ APR_DECLARE(apr_status_t) apr_threadattr_create(apr_threadattr_t **new_attr, apr_pool_t *cont); /** * Set if newly created threads should be created in detached state. * @param attr The threadattr to affect * @param on Non-zero if detached threads should be created. */ APR_DECLARE(apr_status_t) apr_threadattr_detach_set(apr_threadattr_t *attr, apr_int32_t on); /** * Get the detach state for this threadattr. * @param attr The threadattr to reference * @return APR_DETACH if threads are to be detached, or APR_NOTDETACH * if threads are to be joinable. */ APR_DECLARE(apr_status_t) apr_threadattr_detach_get(apr_threadattr_t *attr); /** * Set the stack size of newly created threads. * @param attr The threadattr to affect * @param stacksize The stack size in bytes */ APR_DECLARE(apr_status_t) apr_threadattr_stacksize_set(apr_threadattr_t *attr, apr_size_t stacksize); /** * Set the stack guard area size of newly created threads. * @param attr The threadattr to affect * @param guardsize The stack guard area size in bytes * @note Thread library implementations commonly use a "guard area" * after each thread's stack which is not readable or writable such that * stack overflows cause a segfault; this consumes e.g. 4K of memory * and increases memory management overhead. Setting the guard area * size to zero hence trades off reliable behaviour on stack overflow * for performance. */ APR_DECLARE(apr_status_t) apr_threadattr_guardsize_set(apr_threadattr_t *attr, apr_size_t guardsize); /** * Create a new thread of execution * @param new_thread The newly created thread handle. * @param attr The threadattr to use to determine how to create the thread * @param func The function to start the new thread in * @param data Any data to be passed to the starting function * @param cont The pool to use */ APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new_thread, apr_threadattr_t *attr, apr_thread_start_t func, void *data, apr_pool_t *cont); /** * stop the current thread * @param thd The thread to stop * @param retval The return value to pass back to any thread that cares */ APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd, apr_status_t retval); /** * block until the desired thread stops executing. * @param retval The return value from the dead thread. * @param thd The thread to join */ APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval, apr_thread_t *thd); /** * force the current thread to yield the processor */ APR_DECLARE(void) apr_thread_yield(void); /** * Initialize the control variable for apr_thread_once. If this isn't * called, apr_initialize won't work. * @param control The control variable to initialize * @param p The pool to allocate data from. */ APR_DECLARE(apr_status_t) apr_thread_once_init(apr_thread_once_t **control, apr_pool_t *p); /** * Run the specified function one time, regardless of how many threads * call it. * @param control The control variable. The same variable should * be passed in each time the function is tried to be * called. This is how the underlying functions determine * if the function has ever been called before. * @param func The function to call. */ APR_DECLARE(apr_status_t) apr_thread_once(apr_thread_once_t *control, void (*func)(void)); /** * detach a thread * @param thd The thread to detach */ APR_DECLARE(apr_status_t) apr_thread_detach(apr_thread_t *thd); /** * Return the pool associated with the current thread. * @param data The user data associated with the thread. * @param key The key to associate with the data * @param thread The currently open thread. */ APR_DECLARE(apr_status_t) apr_thread_data_get(void **data, const char *key, apr_thread_t *thread); /** * Return the pool associated with the current thread. * @param data The user data to associate with the thread. * @param key The key to use for associating the data with the thread * @param cleanup The cleanup routine to use when the thread is destroyed. * @param thread The currently open thread. */ APR_DECLARE(apr_status_t) apr_thread_data_set(void *data, const char *key, apr_status_t (*cleanup) (void *), apr_thread_t *thread); /** * Create and initialize a new thread private address space * @param key The thread private handle. * @param dest The destructor to use when freeing the private memory. * @param cont The pool to use */ APR_DECLARE(apr_status_t) apr_threadkey_private_create(apr_threadkey_t **key, void (*dest)(void *), apr_pool_t *cont); /** * Get a pointer to the thread private memory * @param new_mem The data stored in private memory * @param key The handle for the desired thread private memory */ APR_DECLARE(apr_status_t) apr_threadkey_private_get(void **new_mem, apr_threadkey_t *key); /** * Set the data to be stored in thread private memory * @param priv The data to be stored in private memory * @param key The handle for the desired thread private memory */ APR_DECLARE(apr_status_t) apr_threadkey_private_set(void *priv, apr_threadkey_t *key); /** * Free the thread private memory * @param key The handle for the desired thread private memory */ APR_DECLARE(apr_status_t) apr_threadkey_private_delete(apr_threadkey_t *key); /** * Return the pool associated with the current threadkey. * @param data The user data associated with the threadkey. * @param key The key associated with the data * @param threadkey The currently open threadkey. */ APR_DECLARE(apr_status_t) apr_threadkey_data_get(void **data, const char *key, apr_threadkey_t *threadkey); /** * Return the pool associated with the current threadkey. * @param data The data to set. * @param key The key to associate with the data. * @param cleanup The cleanup routine to use when the file is destroyed. * @param threadkey The currently open threadkey. */ APR_DECLARE(apr_status_t) apr_threadkey_data_set(void *data, const char *key, apr_status_t (*cleanup) (void *), apr_threadkey_t *threadkey); #endif /** * Create and initialize a new procattr variable * @param new_attr The newly created procattr. * @param cont The pool to use */ APR_DECLARE(apr_status_t) apr_procattr_create(apr_procattr_t **new_attr, apr_pool_t *cont); /** * Determine if any of stdin, stdout, or stderr should be linked to pipes * when starting a child process. * @param attr The procattr we care about. * @param in Should stdin be a pipe back to the parent? * @param out Should stdout be a pipe back to the parent? * @param err Should stderr be a pipe back to the parent? */ APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr, apr_int32_t in, apr_int32_t out, apr_int32_t err); /** * Set the child_in and/or parent_in values to existing apr_file_t values. * @param attr The procattr we care about. * @param child_in apr_file_t value to use as child_in. Must be a valid file. * @param parent_in apr_file_t value to use as parent_in. Must be a valid file. * @remark This is NOT a required initializer function. This is * useful if you have already opened a pipe (or multiple files) * that you wish to use, perhaps persistently across multiple * process invocations - such as a log file. You can save some * extra function calls by not creating your own pipe since this * creates one in the process space for you. */ APR_DECLARE(apr_status_t) apr_procattr_child_in_set(struct apr_procattr_t *attr, apr_file_t *child_in, apr_file_t *parent_in); /** * Set the child_out and parent_out values to existing apr_file_t values. * @param attr The procattr we care about. * @param child_out apr_file_t value to use as child_out. Must be a valid file. * @param parent_out apr_file_t value to use as parent_out. Must be a valid file. * @remark This is NOT a required initializer function. This is * useful if you have already opened a pipe (or multiple files) * that you wish to use, perhaps persistently across multiple * process invocations - such as a log file. */ APR_DECLARE(apr_status_t) apr_procattr_child_out_set(struct apr_procattr_t *attr, apr_file_t *child_out, apr_file_t *parent_out); /** * Set the child_err and parent_err values to existing apr_file_t values. * @param attr The procattr we care about. * @param child_err apr_file_t value to use as child_err. Must be a valid file. * @param parent_err apr_file_t value to use as parent_err. Must be a valid file. * @remark This is NOT a required initializer function. This is * useful if you have already opened a pipe (or multiple files) * that you wish to use, perhaps persistently across multiple * process invocations - such as a log file. */ APR_DECLARE(apr_status_t) apr_procattr_child_err_set(struct apr_procattr_t *attr, apr_file_t *child_err, apr_file_t *parent_err); /** * Set which directory the child process should start executing in. * @param attr The procattr we care about. * @param dir Which dir to start in. By default, this is the same dir as * the parent currently resides in, when the createprocess call * is made. */ APR_DECLARE(apr_status_t) apr_procattr_dir_set(apr_procattr_t *attr, const char *dir); /** * Set what type of command the child process will call. * @param attr The procattr we care about. * @param cmd The type of command. One of: * <PRE> * APR_SHELLCMD -- Anything that the shell can handle * APR_PROGRAM -- Executable program (default) * APR_PROGRAM_ENV -- Executable program, copy environment * APR_PROGRAM_PATH -- Executable program on PATH, copy env * </PRE> */ APR_DECLARE(apr_status_t) apr_procattr_cmdtype_set(apr_procattr_t *attr, apr_cmdtype_e cmd); /** * Determine if the child should start in detached state. * @param attr The procattr we care about. * @param detach Should the child start in detached state? Default is no. */ APR_DECLARE(apr_status_t) apr_procattr_detach_set(apr_procattr_t *attr, apr_int32_t detach); #if APR_HAVE_STRUCT_RLIMIT /** * Set the Resource Utilization limits when starting a new process. * @param attr The procattr we care about. * @param what Which limit to set, one of: * <PRE> * APR_LIMIT_CPU * APR_LIMIT_MEM * APR_LIMIT_NPROC * APR_LIMIT_NOFILE * </PRE> * @param limit Value to set the limit to. */ APR_DECLARE(apr_status_t) apr_procattr_limit_set(apr_procattr_t *attr, apr_int32_t what, struct rlimit *limit); #endif /** * Specify an error function to be called in the child process if APR * encounters an error in the child prior to running the specified program. * @param attr The procattr describing the child process to be created. * @param errfn The function to call in the child process. * @remark At the present time, it will only be called from apr_proc_create() * on platforms where fork() is used. It will never be called on other * platforms, on those platforms apr_proc_create() will return the error * in the parent process rather than invoke the callback in the now-forked * child process. */ APR_DECLARE(apr_status_t) apr_procattr_child_errfn_set(apr_procattr_t *attr, apr_child_errfn_t *errfn); /** * Specify that apr_proc_create() should do whatever it can to report * failures to the caller of apr_proc_create(), rather than find out in * the child. * @param attr The procattr describing the child process to be created. * @param chk Flag to indicate whether or not extra work should be done * to try to report failures to the caller. * @remark This flag only affects apr_proc_create() on platforms where * fork() is used. This leads to extra overhead in the calling * process, but that may help the application handle such * errors more gracefully. */ APR_DECLARE(apr_status_t) apr_procattr_error_check_set(apr_procattr_t *attr, apr_int32_t chk); /** * Determine if the child should start in its own address space or using the * current one from its parent * @param attr The procattr we care about. * @param addrspace Should the child start in its own address space? Default * is no on NetWare and yes on other platforms. */ APR_DECLARE(apr_status_t) apr_procattr_addrspace_set(apr_procattr_t *attr, apr_int32_t addrspace); /** * Set the username used for running process * @param attr The procattr we care about. * @param username The username used * @param password User password if needed. Password is needed on WIN32 * or any other platform having * APR_PROCATTR_USER_SET_REQUIRES_PASSWORD set. */ APR_DECLARE(apr_status_t) apr_procattr_user_set(apr_procattr_t *attr, const char *username, const char *password); /** * Set the group used for running process * @param attr The procattr we care about. * @param groupname The group name used */ APR_DECLARE(apr_status_t) apr_procattr_group_set(apr_procattr_t *attr, const char *groupname); #if APR_HAS_FORK /** * This is currently the only non-portable call in APR. This executes * a standard unix fork. * @param proc The resulting process handle. * @param cont The pool to use. * @remark returns APR_INCHILD for the child, and APR_INPARENT for the parent * or an error. */ APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *cont); #endif /** * Create a new process and execute a new program within that process. * @param new_proc The resulting process handle. * @param progname The program to run * @param args the arguments to pass to the new program. The first * one should be the program name. * @param env The new environment table for the new process. This * should be a list of NULL-terminated strings. This argument * is ignored for APR_PROGRAM_ENV, APR_PROGRAM_PATH, and * APR_SHELLCMD_ENV types of commands. * @param attr the procattr we should use to determine how to create the new * process * @param pool The pool to use. * @note This function returns without waiting for the new process to terminate; * use apr_proc_wait for that. */ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new_proc, const char *progname, const char * const *args, const char * const *env, apr_procattr_t *attr, apr_pool_t *pool); /** * Wait for a child process to die * @param proc The process handle that corresponds to the desired child process * @param exitcode The returned exit status of the child, if a child process * dies, or the signal that caused the child to die. * On platforms that don't support obtaining this information, * the status parameter will be returned as APR_ENOTIMPL. * @param exitwhy Why the child died, the bitwise or of: * <PRE> * APR_PROC_EXIT -- process terminated normally * APR_PROC_SIGNAL -- process was killed by a signal * APR_PROC_SIGNAL_CORE -- process was killed by a signal, and * generated a core dump. * </PRE> * @param waithow How should we wait. One of: * <PRE> * APR_WAIT -- block until the child process dies. * APR_NOWAIT -- return immediately regardless of if the * child is dead or not. * </PRE> * @remark The childs status is in the return code to this process. It is one of: * <PRE> * APR_CHILD_DONE -- child is no longer running. * APR_CHILD_NOTDONE -- child is still running. * </PRE> */ APR_DECLARE(apr_status_t) apr_proc_wait(apr_proc_t *proc, int *exitcode, apr_exit_why_e *exitwhy, apr_wait_how_e waithow); /** * Wait for any current child process to die and return information * about that child. * @param proc Pointer to NULL on entry, will be filled out with child's * information * @param exitcode The returned exit status of the child, if a child process * dies, or the signal that caused the child to die. * On platforms that don't support obtaining this information, * the status parameter will be returned as APR_ENOTIMPL. * @param exitwhy Why the child died, the bitwise or of: * <PRE> * APR_PROC_EXIT -- process terminated normally * APR_PROC_SIGNAL -- process was killed by a signal * APR_PROC_SIGNAL_CORE -- process was killed by a signal, and * generated a core dump. * </PRE> * @param waithow How should we wait. One of: * <PRE> * APR_WAIT -- block until the child process dies. * APR_NOWAIT -- return immediately regardless of if the * child is dead or not. * </PRE> * @param p Pool to allocate child information out of. * @bug Passing proc as a *proc rather than **proc was an odd choice * for some platforms... this should be revisited in 1.0 */ APR_DECLARE(apr_status_t) apr_proc_wait_all_procs(apr_proc_t *proc, int *exitcode, apr_exit_why_e *exitwhy, apr_wait_how_e waithow, apr_pool_t *p); #define APR_PROC_DETACH_FOREGROUND 0 /**< Do not detach */ #define APR_PROC_DETACH_DAEMONIZE 1 /**< Detach */ /** * Detach the process from the controlling terminal. * @param daemonize set to non-zero if the process should daemonize * and become a background process, else it will * stay in the foreground. */ APR_DECLARE(apr_status_t) apr_proc_detach(int daemonize); /** * Register an other_child -- a child associated to its registered * maintence callback. This callback is invoked when the process * dies, is disconnected or disappears. * @param proc The child process to register. * @param maintenance maintenance is a function that is invoked with a * reason and the data pointer passed here. * @param data Opaque context data passed to the maintenance function. * @param write_fd An fd that is probed for writing. If it is ever unwritable * then the maintenance is invoked with reason * OC_REASON_UNWRITABLE. * @param p The pool to use for allocating memory. * @bug write_fd duplicates the proc->out stream, it's really redundant * and should be replaced in the APR 1.0 API with a bitflag of which * proc->in/out/err handles should be health checked. * @bug no platform currently tests the pipes health. */ APR_DECLARE(void) apr_proc_other_child_register(apr_proc_t *proc, void (*maintenance) (int reason, void *, int status), void *data, apr_file_t *write_fd, apr_pool_t *p); /** * Stop watching the specified other child. * @param data The data to pass to the maintenance function. This is * used to find the process to unregister. * @warning Since this can be called by a maintenance function while we're * scanning the other_children list, all scanners should protect * themself by loading ocr->next before calling any maintenance * function. */ APR_DECLARE(void) apr_proc_other_child_unregister(void *data); /** * Notify the maintenance callback of a registered other child process * that application has detected an event, such as death. * @param proc The process to check * @param reason The reason code to pass to the maintenance function * @param status The status to pass to the maintenance function * @remark An example of code using this behavior; * <pre> * rv = apr_proc_wait_all_procs(&proc, &exitcode, &status, APR_WAIT, p); * if (APR_STATUS_IS_CHILD_DONE(rv)) { * #if APR_HAS_OTHER_CHILD * if (apr_proc_other_child_alert(&proc, APR_OC_REASON_DEATH, status) * == APR_SUCCESS) { * ; (already handled) * } * else * #endif * [... handling non-otherchild processes death ...] * </pre> */ APR_DECLARE(apr_status_t) apr_proc_other_child_alert(apr_proc_t *proc, int reason, int status); /** * Test one specific other child processes and invoke the maintenance callback * with the appropriate reason code, if still running, or the appropriate reason * code if the process is no longer healthy. * @param ocr The registered other child * @param reason The reason code (e.g. APR_OC_REASON_RESTART) if still running */ APR_DECLARE(void) apr_proc_other_child_refresh(apr_other_child_rec_t *ocr, int reason); /** * Test all registered other child processes and invoke the maintenance callback * with the appropriate reason code, if still running, or the appropriate reason * code if the process is no longer healthy. * @param reason The reason code (e.g. APR_OC_REASON_RESTART) to running processes */ APR_DECLARE(void) apr_proc_other_child_refresh_all(int reason); /** * Terminate a process. * @param proc The process to terminate. * @param sig How to kill the process. */ APR_DECLARE(apr_status_t) apr_proc_kill(apr_proc_t *proc, int sig); /** * Register a process to be killed when a pool dies. * @param a The pool to use to define the processes lifetime * @param proc The process to register * @param how How to kill the process, one of: * <PRE> * APR_KILL_NEVER -- process is never sent any signals * APR_KILL_ALWAYS -- process is sent SIGKILL on apr_pool_t cleanup * APR_KILL_AFTER_TIMEOUT -- SIGTERM, wait 3 seconds, SIGKILL * APR_JUST_WAIT -- wait forever for the process to complete * APR_KILL_ONLY_ONCE -- send SIGTERM and then wait * </PRE> */ APR_DECLARE(void) apr_pool_note_subprocess(apr_pool_t *a, apr_proc_t *proc, apr_kill_conditions_e how); #if APR_HAS_THREADS #if (APR_HAVE_SIGWAIT || APR_HAVE_SIGSUSPEND) && !defined(OS2) /** * Setup the process for a single thread to be used for all signal handling. * @warning This must be called before any threads are created */ APR_DECLARE(apr_status_t) apr_setup_signal_thread(void); /** * Make the current thread listen for signals. This thread will loop * forever, calling a provided function whenever it receives a signal. That * functions should return 1 if the signal has been handled, 0 otherwise. * @param signal_handler The function to call when a signal is received * apr_status_t apr_signal_thread((int)(*signal_handler)(int signum)) */ APR_DECLARE(apr_status_t) apr_signal_thread(int(*signal_handler)(int signum)); #endif /* (APR_HAVE_SIGWAIT || APR_HAVE_SIGSUSPEND) && !defined(OS2) */ /** * Get the child-pool used by the thread from the thread info. * @return apr_pool_t the pool */ APR_POOL_DECLARE_ACCESSOR(thread); #endif /* APR_HAS_THREADS */ /** @} */ #ifdef __cplusplus } #endif #endif /* ! APR_THREAD_PROC_H */
001-log4cxx
trunk/src/apr/include/apr_thread_proc.h
C
asf20
33,437
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef APR_ALLOCATOR_H #define APR_ALLOCATOR_H /** * @file apr_allocator.h * @brief APR Internal Memory Allocation */ #include "apr.h" #include "apr_errno.h" #define APR_WANT_MEMFUNC /**< For no good reason? */ #include "apr_want.h" #ifdef __cplusplus extern "C" { #endif /** * @defgroup apr_allocator Internal Memory Allocation * @ingroup APR * @{ */ /** the allocator structure */ typedef struct apr_allocator_t apr_allocator_t; /** the structure which holds information about the allocation */ typedef struct apr_memnode_t apr_memnode_t; /** basic memory node structure * @note The next, ref and first_avail fields are available for use by the * caller of apr_allocator_alloc(), the remaining fields are read-only. * The next field has to be used with caution and sensibly set when the * memnode is passed back to apr_allocator_free(). See apr_allocator_free() * for details. * The ref and first_avail fields will be properly restored by * apr_allocator_free(). */ struct apr_memnode_t { apr_memnode_t *next; /**< next memnode */ apr_memnode_t **ref; /**< reference to self */ apr_uint32_t index; /**< size */ apr_uint32_t free_index; /**< how much free */ char *first_avail; /**< pointer to first free memory */ char *endp; /**< pointer to end of free memory */ }; /** The base size of a memory node - aligned. */ #define APR_MEMNODE_T_SIZE APR_ALIGN_DEFAULT(sizeof(apr_memnode_t)) /** Symbolic constants */ #define APR_ALLOCATOR_MAX_FREE_UNLIMITED 0 /** * Create a new allocator * @param allocator The allocator we have just created. * */ APR_DECLARE(apr_status_t) apr_allocator_create(apr_allocator_t **allocator); /** * Destroy an allocator * @param allocator The allocator to be destroyed * @remark Any memnodes not given back to the allocator prior to destroying * will _not_ be free()d. */ APR_DECLARE(void) apr_allocator_destroy(apr_allocator_t *allocator); /** * Allocate a block of mem from the allocator * @param allocator The allocator to allocate from * @param size The size of the mem to allocate (excluding the * memnode structure) */ APR_DECLARE(apr_memnode_t *) apr_allocator_alloc(apr_allocator_t *allocator, apr_size_t size); /** * Free a list of blocks of mem, giving them back to the allocator. * The list is typically terminated by a memnode with its next field * set to NULL. * @param allocator The allocator to give the mem back to * @param memnode The memory node to return */ APR_DECLARE(void) apr_allocator_free(apr_allocator_t *allocator, apr_memnode_t *memnode); #include "apr_pools.h" /** * Set the owner of the allocator * @param allocator The allocator to set the owner for * @param pool The pool that is to own the allocator * @remark Typically pool is the highest level pool using the allocator */ /* * XXX: see if we can come up with something a bit better. Currently * you can make a pool an owner, but if the pool doesn't use the allocator * the allocator will never be destroyed. */ APR_DECLARE(void) apr_allocator_owner_set(apr_allocator_t *allocator, apr_pool_t *pool); /** * Get the current owner of the allocator * @param allocator The allocator to get the owner from */ APR_DECLARE(apr_pool_t *) apr_allocator_owner_get(apr_allocator_t *allocator); /** * Set the current threshold at which the allocator should start * giving blocks back to the system. * @param allocator The allocator the set the threshold on * @param size The threshold. 0 == unlimited. */ APR_DECLARE(void) apr_allocator_max_free_set(apr_allocator_t *allocator, apr_size_t size); #include "apr_thread_mutex.h" #if APR_HAS_THREADS /** * Set a mutex for the allocator to use * @param allocator The allocator to set the mutex for * @param mutex The mutex */ APR_DECLARE(void) apr_allocator_mutex_set(apr_allocator_t *allocator, apr_thread_mutex_t *mutex); /** * Get the mutex currently set for the allocator * @param allocator The allocator */ APR_DECLARE(apr_thread_mutex_t *) apr_allocator_mutex_get( apr_allocator_t *allocator); #endif /* APR_HAS_THREADS */ /** @} */ #ifdef __cplusplus } #endif #endif /* !APR_ALLOCATOR_H */
001-log4cxx
trunk/src/apr/include/apr_allocator.h
C
asf20
5,334
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef APR_GETOPT_H #define APR_GETOPT_H /** * @file apr_getopt.h * @brief APR Command Arguments (getopt) */ #include "apr_pools.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /** * @defgroup apr_getopt Command Argument Parsing * @ingroup APR * @{ */ /** * defintion of a error function */ typedef void (apr_getopt_err_fn_t)(void *arg, const char *err, ...); /** @see apr_getopt_t */ typedef struct apr_getopt_t apr_getopt_t; /** * Structure to store command line argument information. */ struct apr_getopt_t { /** context for processing */ apr_pool_t *cont; /** function to print error message (NULL == no messages) */ apr_getopt_err_fn_t *errfn; /** user defined first arg to pass to error message */ void *errarg; /** index into parent argv vector */ int ind; /** character checked for validity */ int opt; /** reset getopt */ int reset; /** count of arguments */ int argc; /** array of pointers to arguments */ const char **argv; /** argument associated with option */ char const* place; /** set to nonzero to support interleaving options with regular args */ int interleave; /** start of non-option arguments skipped for interleaving */ int skip_start; /** end of non-option arguments skipped for interleaving */ int skip_end; }; /** @see apr_getopt_option_t */ typedef struct apr_getopt_option_t apr_getopt_option_t; /** * Structure used to describe options that getopt should search for. */ struct apr_getopt_option_t { /** long option name, or NULL if option has no long name */ const char *name; /** option letter, or a value greater than 255 if option has no letter */ int optch; /** nonzero if option takes an argument */ int has_arg; /** a description of the option */ const char *description; }; /** * Initialize the arguments for parsing by apr_getopt(). * @param os The options structure created for apr_getopt() * @param cont The pool to operate on * @param argc The number of arguments to parse * @param argv The array of arguments to parse * @remark Arguments 2 and 3 are most commonly argc and argv from main(argc, argv) * The errfn is initialized to fprintf(stderr... but may be overridden. */ APR_DECLARE(apr_status_t) apr_getopt_init(apr_getopt_t **os, apr_pool_t *cont, int argc, const char * const *argv); /** * Parse the options initialized by apr_getopt_init(). * @param os The apr_opt_t structure returned by apr_getopt_init() * @param opts A string of characters that are acceptable options to the * program. Characters followed by ":" are required to have an * option associated * @param option_ch The next option character parsed * @param option_arg The argument following the option character: * @return There are four potential status values on exit. They are: * <PRE> * APR_EOF -- No more options to parse * APR_BADCH -- Found a bad option character * APR_BADARG -- No argument followed the option flag * APR_SUCCESS -- The next option was found. * </PRE> */ APR_DECLARE(apr_status_t) apr_getopt(apr_getopt_t *os, const char *opts, char *option_ch, const char **option_arg); /** * Parse the options initialized by apr_getopt_init(), accepting long * options beginning with "--" in addition to single-character * options beginning with "-". * @param os The apr_getopt_t structure created by apr_getopt_init() * @param opts A pointer to a list of apr_getopt_option_t structures, which * can be initialized with { "name", optch, has_args }. has_args * is nonzero if the option requires an argument. A structure * with an optch value of 0 terminates the list. * @param option_ch Receives the value of "optch" from the apr_getopt_option_t * structure corresponding to the next option matched. * @param option_arg Receives the argument following the option, if any. * @return There are four potential status values on exit. They are: * <PRE> * APR_EOF -- No more options to parse * APR_BADCH -- Found a bad option character * APR_BADARG -- No argument followed the option flag * APR_SUCCESS -- The next option was found. * </PRE> * When APR_SUCCESS is returned, os->ind gives the index of the first * non-option argument. On error, a message will be printed to stdout unless * os->err is set to 0. If os->interleave is set to nonzero, options can come * after arguments, and os->argv will be permuted to leave non-option arguments * at the end (the original argv is unaffected). */ APR_DECLARE(apr_status_t) apr_getopt_long(apr_getopt_t *os, const apr_getopt_option_t *opts, int *option_ch, const char **option_arg); /** @} */ #ifdef __cplusplus } #endif #endif /* ! APR_GETOPT_H */
001-log4cxx
trunk/src/apr/include/apr_getopt.h
C
asf20
5,903
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef APR_RANDOM_H #define APR_RANDOM_H #include <apr_pools.h> typedef struct apr_crypto_hash_t apr_crypto_hash_t; typedef void apr_crypto_hash_init_t(apr_crypto_hash_t *hash); typedef void apr_crypto_hash_add_t(apr_crypto_hash_t *hash,const void *data, apr_size_t bytes); typedef void apr_crypto_hash_finish_t(apr_crypto_hash_t *hash, unsigned char *result); /* FIXME: make this opaque */ struct apr_crypto_hash_t { apr_crypto_hash_init_t *init; apr_crypto_hash_add_t *add; apr_crypto_hash_finish_t *finish; apr_size_t size; void *data; }; APR_DECLARE(apr_crypto_hash_t *) apr_crypto_sha256_new(apr_pool_t *p); typedef struct apr_random_t apr_random_t; APR_DECLARE(void) apr_random_init(apr_random_t *g,apr_pool_t *p, apr_crypto_hash_t *pool_hash, apr_crypto_hash_t *key_hash, apr_crypto_hash_t *prng_hash); APR_DECLARE(apr_random_t *) apr_random_standard_new(apr_pool_t *p); APR_DECLARE(void) apr_random_add_entropy(apr_random_t *g, const void *entropy_, apr_size_t bytes); APR_DECLARE(apr_status_t) apr_random_insecure_bytes(apr_random_t *g, void *random, apr_size_t bytes); APR_DECLARE(apr_status_t) apr_random_secure_bytes(apr_random_t *g, void *random, apr_size_t bytes); APR_DECLARE(void) apr_random_barrier(apr_random_t *g); APR_DECLARE(apr_status_t) apr_random_secure_ready(apr_random_t *r); APR_DECLARE(apr_status_t) apr_random_insecure_ready(apr_random_t *r); /* Call this in the child after forking to mix the randomness pools. Note that its generally a bad idea to fork a process with a real PRNG in it - better to have the PRNG externally and get the randomness from there. However, if you really must do it, then you should supply all your entropy to all the PRNGs - don't worry, they won't produce the same output. Note that apr_proc_fork() calls this for you, so only weird applications need ever call it themselves. */ struct apr_proc_t; APR_DECLARE(void) apr_random_after_fork(struct apr_proc_t *proc); #endif /* ndef APR_RANDOM_H */
001-log4cxx
trunk/src/apr/include/apr_random.h
C
asf20
3,267
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef APR_SUPPORT_H #define APR_SUPPORT_H /** * @file apr_support.h * @brief APR Support functions */ #include "apr.h" #include "apr_network_io.h" #include "apr_file_io.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /** * @defgroup apr_support Internal APR support functions * @ingroup APR * @{ */ /** * Wait for IO to occur or timeout. * * Uses POOL for temporary allocations. */ apr_status_t apr_wait_for_io_or_timeout(apr_file_t *f, apr_socket_t *s, int for_read); /** @} */ #ifdef __cplusplus } #endif #endif /* ! APR_SUPPORT_H */
001-log4cxx
trunk/src/apr/include/apr_support.h
C
asf20
1,411
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef APR_ERRNO_H #define APR_ERRNO_H /** * @file apr_errno.h * @brief APR Error Codes */ #include "apr.h" #if APR_HAVE_ERRNO_H #include <errno.h> #endif #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /** * @defgroup apr_errno Error Codes * @ingroup APR * @{ */ /** * Type for specifying an error or status code. */ typedef int apr_status_t; /** * Return a human readable string describing the specified error. * @param statcode The error code the get a string for. * @param buf A buffer to hold the error string. * @param bufsize Size of the buffer to hold the string. */ APR_DECLARE(char *) apr_strerror(apr_status_t statcode, char *buf, apr_size_t bufsize); #if defined(DOXYGEN) /** * @def APR_FROM_OS_ERROR(os_err_type syserr) * Fold a platform specific error into an apr_status_t code. * @return apr_status_t * @param e The platform os error code. * @warning macro implementation; the syserr argument may be evaluated * multiple times. */ #define APR_FROM_OS_ERROR(e) (e == 0 ? APR_SUCCESS : e + APR_OS_START_SYSERR) /** * @def APR_TO_OS_ERROR(apr_status_t statcode) * @return os_err_type * Fold an apr_status_t code back to the native platform defined error. * @param e The apr_status_t folded platform os error code. * @warning macro implementation; the statcode argument may be evaluated * multiple times. If the statcode was not created by apr_get_os_error * or APR_FROM_OS_ERROR, the results are undefined. */ #define APR_TO_OS_ERROR(e) (e == 0 ? APR_SUCCESS : e - APR_OS_START_SYSERR) /** @def apr_get_os_error() * @return apr_status_t the last platform error, folded into apr_status_t, on most platforms * @remark This retrieves errno, or calls a GetLastError() style function, and * folds it with APR_FROM_OS_ERROR. Some platforms (such as OS2) have no * such mechanism, so this call may be unsupported. Do NOT use this * call for socket errors from socket, send, recv etc! */ /** @def apr_set_os_error(e) * Reset the last platform error, unfolded from an apr_status_t, on some platforms * @param e The OS error folded in a prior call to APR_FROM_OS_ERROR() * @warning This is a macro implementation; the statcode argument may be evaluated * multiple times. If the statcode was not created by apr_get_os_error * or APR_FROM_OS_ERROR, the results are undefined. This macro sets * errno, or calls a SetLastError() style function, unfolding statcode * with APR_TO_OS_ERROR. Some platforms (such as OS2) have no such * mechanism, so this call may be unsupported. */ /** @def apr_get_netos_error() * Return the last socket error, folded into apr_status_t, on all platforms * @remark This retrieves errno or calls a GetLastSocketError() style function, * and folds it with APR_FROM_OS_ERROR. */ /** @def apr_set_netos_error(e) * Reset the last socket error, unfolded from an apr_status_t * @param e The socket error folded in a prior call to APR_FROM_OS_ERROR() * @warning This is a macro implementation; the statcode argument may be evaluated * multiple times. If the statcode was not created by apr_get_os_error * or APR_FROM_OS_ERROR, the results are undefined. This macro sets * errno, or calls a WSASetLastError() style function, unfolding * socketcode with APR_TO_OS_ERROR. */ #endif /* defined(DOXYGEN) */ /** * APR_OS_START_ERROR is where the APR specific error values start. */ #define APR_OS_START_ERROR 20000 /** * APR_OS_ERRSPACE_SIZE is the maximum number of errors you can fit * into one of the error/status ranges below -- except for * APR_OS_START_USERERR, which see. */ #define APR_OS_ERRSPACE_SIZE 50000 /** * APR_OS_START_STATUS is where the APR specific status codes start. */ #define APR_OS_START_STATUS (APR_OS_START_ERROR + APR_OS_ERRSPACE_SIZE) /** * APR_OS_START_USERERR are reserved for applications that use APR that * layer their own error codes along with APR's. Note that the * error immediately following this one is set ten times farther * away than usual, so that users of apr have a lot of room in * which to declare custom error codes. */ #define APR_OS_START_USERERR (APR_OS_START_STATUS + APR_OS_ERRSPACE_SIZE) /** * APR_OS_START_USEERR is obsolete, defined for compatibility only. * Use APR_OS_START_USERERR instead. */ #define APR_OS_START_USEERR APR_OS_START_USERERR /** * APR_OS_START_CANONERR is where APR versions of errno values are defined * on systems which don't have the corresponding errno. */ #define APR_OS_START_CANONERR (APR_OS_START_USERERR \ + (APR_OS_ERRSPACE_SIZE * 10)) /** * APR_OS_START_EAIERR folds EAI_ error codes from getaddrinfo() into * apr_status_t values. */ #define APR_OS_START_EAIERR (APR_OS_START_CANONERR + APR_OS_ERRSPACE_SIZE) /** * APR_OS_START_SYSERR folds platform-specific system error values into * apr_status_t values. */ #define APR_OS_START_SYSERR (APR_OS_START_EAIERR + APR_OS_ERRSPACE_SIZE) /** no error. */ #define APR_SUCCESS 0 /** * @defgroup APR_Error APR Error Values * <PRE> * <b>APR ERROR VALUES</b> * APR_ENOSTAT APR was unable to perform a stat on the file * APR_ENOPOOL APR was not provided a pool with which to allocate memory * APR_EBADDATE APR was given an invalid date * APR_EINVALSOCK APR was given an invalid socket * APR_ENOPROC APR was not given a process structure * APR_ENOTIME APR was not given a time structure * APR_ENODIR APR was not given a directory structure * APR_ENOLOCK APR was not given a lock structure * APR_ENOPOLL APR was not given a poll structure * APR_ENOSOCKET APR was not given a socket * APR_ENOTHREAD APR was not given a thread structure * APR_ENOTHDKEY APR was not given a thread key structure * APR_ENOSHMAVAIL There is no more shared memory available * APR_EDSOOPEN APR was unable to open the dso object. For more * information call apr_dso_error(). * APR_EGENERAL General failure (specific information not available) * APR_EBADIP The specified IP address is invalid * APR_EBADMASK The specified netmask is invalid * APR_ESYMNOTFOUND Could not find the requested symbol * </PRE> * * <PRE> * <b>APR STATUS VALUES</b> * APR_INCHILD Program is currently executing in the child * APR_INPARENT Program is currently executing in the parent * APR_DETACH The thread is detached * APR_NOTDETACH The thread is not detached * APR_CHILD_DONE The child has finished executing * APR_CHILD_NOTDONE The child has not finished executing * APR_TIMEUP The operation did not finish before the timeout * APR_INCOMPLETE The operation was incomplete although some processing * was performed and the results are partially valid * APR_BADCH Getopt found an option not in the option string * APR_BADARG Getopt found an option that is missing an argument * and an argument was specified in the option string * APR_EOF APR has encountered the end of the file * APR_NOTFOUND APR was unable to find the socket in the poll structure * APR_ANONYMOUS APR is using anonymous shared memory * APR_FILEBASED APR is using a file name as the key to the shared memory * APR_KEYBASED APR is using a shared key as the key to the shared memory * APR_EINIT Ininitalizer value. If no option has been found, but * the status variable requires a value, this should be used * APR_ENOTIMPL The APR function has not been implemented on this * platform, either because nobody has gotten to it yet, * or the function is impossible on this platform. * APR_EMISMATCH Two passwords do not match. * APR_EABSOLUTE The given path was absolute. * APR_ERELATIVE The given path was relative. * APR_EINCOMPLETE The given path was neither relative nor absolute. * APR_EABOVEROOT The given path was above the root path. * APR_EBUSY The given lock was busy. * APR_EPROC_UNKNOWN The given process wasn't recognized by APR * </PRE> * @{ */ /** @see APR_STATUS_IS_ENOSTAT */ #define APR_ENOSTAT (APR_OS_START_ERROR + 1) /** @see APR_STATUS_IS_ENOPOOL */ #define APR_ENOPOOL (APR_OS_START_ERROR + 2) /* empty slot: +3 */ /** @see APR_STATUS_IS_EBADDATE */ #define APR_EBADDATE (APR_OS_START_ERROR + 4) /** @see APR_STATUS_IS_EINVALSOCK */ #define APR_EINVALSOCK (APR_OS_START_ERROR + 5) /** @see APR_STATUS_IS_ENOPROC */ #define APR_ENOPROC (APR_OS_START_ERROR + 6) /** @see APR_STATUS_IS_ENOTIME */ #define APR_ENOTIME (APR_OS_START_ERROR + 7) /** @see APR_STATUS_IS_ENODIR */ #define APR_ENODIR (APR_OS_START_ERROR + 8) /** @see APR_STATUS_IS_ENOLOCK */ #define APR_ENOLOCK (APR_OS_START_ERROR + 9) /** @see APR_STATUS_IS_ENOPOLL */ #define APR_ENOPOLL (APR_OS_START_ERROR + 10) /** @see APR_STATUS_IS_ENOSOCKET */ #define APR_ENOSOCKET (APR_OS_START_ERROR + 11) /** @see APR_STATUS_IS_ENOTHREAD */ #define APR_ENOTHREAD (APR_OS_START_ERROR + 12) /** @see APR_STATUS_IS_ENOTHDKEY */ #define APR_ENOTHDKEY (APR_OS_START_ERROR + 13) /** @see APR_STATUS_IS_EGENERAL */ #define APR_EGENERAL (APR_OS_START_ERROR + 14) /** @see APR_STATUS_IS_ENOSHMAVAIL */ #define APR_ENOSHMAVAIL (APR_OS_START_ERROR + 15) /** @see APR_STATUS_IS_EBADIP */ #define APR_EBADIP (APR_OS_START_ERROR + 16) /** @see APR_STATUS_IS_EBADMASK */ #define APR_EBADMASK (APR_OS_START_ERROR + 17) /* empty slot: +18 */ /** @see APR_STATUS_IS_EDSOPEN */ #define APR_EDSOOPEN (APR_OS_START_ERROR + 19) /** @see APR_STATUS_IS_EABSOLUTE */ #define APR_EABSOLUTE (APR_OS_START_ERROR + 20) /** @see APR_STATUS_IS_ERELATIVE */ #define APR_ERELATIVE (APR_OS_START_ERROR + 21) /** @see APR_STATUS_IS_EINCOMPLETE */ #define APR_EINCOMPLETE (APR_OS_START_ERROR + 22) /** @see APR_STATUS_IS_EABOVEROOT */ #define APR_EABOVEROOT (APR_OS_START_ERROR + 23) /** @see APR_STATUS_IS_EBADPATH */ #define APR_EBADPATH (APR_OS_START_ERROR + 24) /** @see APR_STATUS_IS_EPATHWILD */ #define APR_EPATHWILD (APR_OS_START_ERROR + 25) /** @see APR_STATUS_IS_ESYMNOTFOUND */ #define APR_ESYMNOTFOUND (APR_OS_START_ERROR + 26) /** @see APR_STATUS_IS_EPROC_UNKNOWN */ #define APR_EPROC_UNKNOWN (APR_OS_START_ERROR + 27) /** @see APR_STATUS_IS_ENOTENOUGHENTROPY */ #define APR_ENOTENOUGHENTROPY (APR_OS_START_ERROR + 28) /** @} */ /** * @defgroup APR_STATUS_IS Status Value Tests * @warning For any particular error condition, more than one of these tests * may match. This is because platform-specific error codes may not * always match the semantics of the POSIX codes these tests (and the * corresponding APR error codes) are named after. A notable example * are the APR_STATUS_IS_ENOENT and APR_STATUS_IS_ENOTDIR tests on * Win32 platforms. The programmer should always be aware of this and * adjust the order of the tests accordingly. * @{ */ /** * APR was unable to perform a stat on the file * @warning always use this test, as platform-specific variances may meet this * more than one error code */ #define APR_STATUS_IS_ENOSTAT(s) ((s) == APR_ENOSTAT) /** * APR was not provided a pool with which to allocate memory * @warning always use this test, as platform-specific variances may meet this * more than one error code */ #define APR_STATUS_IS_ENOPOOL(s) ((s) == APR_ENOPOOL) /** APR was given an invalid date */ #define APR_STATUS_IS_EBADDATE(s) ((s) == APR_EBADDATE) /** APR was given an invalid socket */ #define APR_STATUS_IS_EINVALSOCK(s) ((s) == APR_EINVALSOCK) /** APR was not given a process structure */ #define APR_STATUS_IS_ENOPROC(s) ((s) == APR_ENOPROC) /** APR was not given a time structure */ #define APR_STATUS_IS_ENOTIME(s) ((s) == APR_ENOTIME) /** APR was not given a directory structure */ #define APR_STATUS_IS_ENODIR(s) ((s) == APR_ENODIR) /** APR was not given a lock structure */ #define APR_STATUS_IS_ENOLOCK(s) ((s) == APR_ENOLOCK) /** APR was not given a poll structure */ #define APR_STATUS_IS_ENOPOLL(s) ((s) == APR_ENOPOLL) /** APR was not given a socket */ #define APR_STATUS_IS_ENOSOCKET(s) ((s) == APR_ENOSOCKET) /** APR was not given a thread structure */ #define APR_STATUS_IS_ENOTHREAD(s) ((s) == APR_ENOTHREAD) /** APR was not given a thread key structure */ #define APR_STATUS_IS_ENOTHDKEY(s) ((s) == APR_ENOTHDKEY) /** Generic Error which can not be put into another spot */ #define APR_STATUS_IS_EGENERAL(s) ((s) == APR_EGENERAL) /** There is no more shared memory available */ #define APR_STATUS_IS_ENOSHMAVAIL(s) ((s) == APR_ENOSHMAVAIL) /** The specified IP address is invalid */ #define APR_STATUS_IS_EBADIP(s) ((s) == APR_EBADIP) /** The specified netmask is invalid */ #define APR_STATUS_IS_EBADMASK(s) ((s) == APR_EBADMASK) /* empty slot: +18 */ /** * APR was unable to open the dso object. * For more information call apr_dso_error(). */ #if defined(WIN32) #define APR_STATUS_IS_EDSOOPEN(s) ((s) == APR_EDSOOPEN \ || APR_TO_OS_ERROR(s) == ERROR_MOD_NOT_FOUND) #else #define APR_STATUS_IS_EDSOOPEN(s) ((s) == APR_EDSOOPEN) #endif /** The given path was absolute. */ #define APR_STATUS_IS_EABSOLUTE(s) ((s) == APR_EABSOLUTE) /** The given path was relative. */ #define APR_STATUS_IS_ERELATIVE(s) ((s) == APR_ERELATIVE) /** The given path was neither relative nor absolute. */ #define APR_STATUS_IS_EINCOMPLETE(s) ((s) == APR_EINCOMPLETE) /** The given path was above the root path. */ #define APR_STATUS_IS_EABOVEROOT(s) ((s) == APR_EABOVEROOT) /** The given path was bad. */ #define APR_STATUS_IS_EBADPATH(s) ((s) == APR_EBADPATH) /** The given path contained wildcards. */ #define APR_STATUS_IS_EPATHWILD(s) ((s) == APR_EPATHWILD) /** Could not find the requested symbol. * For more information call apr_dso_error(). */ #if defined(WIN32) #define APR_STATUS_IS_ESYMNOTFOUND(s) ((s) == APR_ESYMNOTFOUND \ || APR_TO_OS_ERROR(s) == ERROR_PROC_NOT_FOUND) #else #define APR_STATUS_IS_ESYMNOTFOUND(s) ((s) == APR_ESYMNOTFOUND) #endif /** The given process was not recognized by APR. */ #define APR_STATUS_IS_EPROC_UNKNOWN(s) ((s) == APR_EPROC_UNKNOWN) /** APR could not gather enough entropy to continue. */ #define APR_STATUS_IS_ENOTENOUGHENTROPY(s) ((s) == APR_ENOTENOUGHENTROPY) /** @} */ /** * @addtogroup APR_Error * @{ */ /** @see APR_STATUS_IS_INCHILD */ #define APR_INCHILD (APR_OS_START_STATUS + 1) /** @see APR_STATUS_IS_INPARENT */ #define APR_INPARENT (APR_OS_START_STATUS + 2) /** @see APR_STATUS_IS_DETACH */ #define APR_DETACH (APR_OS_START_STATUS + 3) /** @see APR_STATUS_IS_NOTDETACH */ #define APR_NOTDETACH (APR_OS_START_STATUS + 4) /** @see APR_STATUS_IS_CHILD_DONE */ #define APR_CHILD_DONE (APR_OS_START_STATUS + 5) /** @see APR_STATUS_IS_CHILD_NOTDONE */ #define APR_CHILD_NOTDONE (APR_OS_START_STATUS + 6) /** @see APR_STATUS_IS_TIMEUP */ #define APR_TIMEUP (APR_OS_START_STATUS + 7) /** @see APR_STATUS_IS_INCOMPLETE */ #define APR_INCOMPLETE (APR_OS_START_STATUS + 8) /* empty slot: +9 */ /* empty slot: +10 */ /* empty slot: +11 */ /** @see APR_STATUS_IS_BADCH */ #define APR_BADCH (APR_OS_START_STATUS + 12) /** @see APR_STATUS_IS_BADARG */ #define APR_BADARG (APR_OS_START_STATUS + 13) /** @see APR_STATUS_IS_EOF */ #define APR_EOF (APR_OS_START_STATUS + 14) /** @see APR_STATUS_IS_NOTFOUND */ #define APR_NOTFOUND (APR_OS_START_STATUS + 15) /* empty slot: +16 */ /* empty slot: +17 */ /* empty slot: +18 */ /** @see APR_STATUS_IS_ANONYMOUS */ #define APR_ANONYMOUS (APR_OS_START_STATUS + 19) /** @see APR_STATUS_IS_FILEBASED */ #define APR_FILEBASED (APR_OS_START_STATUS + 20) /** @see APR_STATUS_IS_KEYBASED */ #define APR_KEYBASED (APR_OS_START_STATUS + 21) /** @see APR_STATUS_IS_EINIT */ #define APR_EINIT (APR_OS_START_STATUS + 22) /** @see APR_STATUS_IS_ENOTIMPL */ #define APR_ENOTIMPL (APR_OS_START_STATUS + 23) /** @see APR_STATUS_IS_EMISMATCH */ #define APR_EMISMATCH (APR_OS_START_STATUS + 24) /** @see APR_STATUS_IS_EBUSY */ #define APR_EBUSY (APR_OS_START_STATUS + 25) /** @} */ /** * @addtogroup APR_STATUS_IS * @{ */ /** * Program is currently executing in the child * @warning * always use this test, as platform-specific variances may meet this * more than one error code */ #define APR_STATUS_IS_INCHILD(s) ((s) == APR_INCHILD) /** * Program is currently executing in the parent * @warning * always use this test, as platform-specific variances may meet this * more than one error code */ #define APR_STATUS_IS_INPARENT(s) ((s) == APR_INPARENT) /** * The thread is detached * @warning * always use this test, as platform-specific variances may meet this * more than one error code */ #define APR_STATUS_IS_DETACH(s) ((s) == APR_DETACH) /** * The thread is not detached * @warning * always use this test, as platform-specific variances may meet this * more than one error code */ #define APR_STATUS_IS_NOTDETACH(s) ((s) == APR_NOTDETACH) /** * The child has finished executing * @warning * always use this test, as platform-specific variances may meet this * more than one error code */ #define APR_STATUS_IS_CHILD_DONE(s) ((s) == APR_CHILD_DONE) /** * The child has not finished executing * @warning * always use this test, as platform-specific variances may meet this * more than one error code */ #define APR_STATUS_IS_CHILD_NOTDONE(s) ((s) == APR_CHILD_NOTDONE) /** * The operation did not finish before the timeout * @warning * always use this test, as platform-specific variances may meet this * more than one error code */ #define APR_STATUS_IS_TIMEUP(s) ((s) == APR_TIMEUP) /** * The operation was incomplete although some processing was performed * and the results are partially valid. * @warning * always use this test, as platform-specific variances may meet this * more than one error code */ #define APR_STATUS_IS_INCOMPLETE(s) ((s) == APR_INCOMPLETE) /* empty slot: +9 */ /* empty slot: +10 */ /* empty slot: +11 */ /** * Getopt found an option not in the option string * @warning * always use this test, as platform-specific variances may meet this * more than one error code */ #define APR_STATUS_IS_BADCH(s) ((s) == APR_BADCH) /** * Getopt found an option not in the option string and an argument was * specified in the option string * @warning * always use this test, as platform-specific variances may meet this * more than one error code */ #define APR_STATUS_IS_BADARG(s) ((s) == APR_BADARG) /** * APR has encountered the end of the file * @warning * always use this test, as platform-specific variances may meet this * more than one error code */ #define APR_STATUS_IS_EOF(s) ((s) == APR_EOF) /** * APR was unable to find the socket in the poll structure * @warning * always use this test, as platform-specific variances may meet this * more than one error code */ #define APR_STATUS_IS_NOTFOUND(s) ((s) == APR_NOTFOUND) /* empty slot: +16 */ /* empty slot: +17 */ /* empty slot: +18 */ /** * APR is using anonymous shared memory * @warning * always use this test, as platform-specific variances may meet this * more than one error code */ #define APR_STATUS_IS_ANONYMOUS(s) ((s) == APR_ANONYMOUS) /** * APR is using a file name as the key to the shared memory * @warning * always use this test, as platform-specific variances may meet this * more than one error code */ #define APR_STATUS_IS_FILEBASED(s) ((s) == APR_FILEBASED) /** * APR is using a shared key as the key to the shared memory * @warning * always use this test, as platform-specific variances may meet this * more than one error code */ #define APR_STATUS_IS_KEYBASED(s) ((s) == APR_KEYBASED) /** * Ininitalizer value. If no option has been found, but * the status variable requires a value, this should be used * @warning * always use this test, as platform-specific variances may meet this * more than one error code */ #define APR_STATUS_IS_EINIT(s) ((s) == APR_EINIT) /** * The APR function has not been implemented on this * platform, either because nobody has gotten to it yet, * or the function is impossible on this platform. * @warning * always use this test, as platform-specific variances may meet this * more than one error code */ #define APR_STATUS_IS_ENOTIMPL(s) ((s) == APR_ENOTIMPL) /** * Two passwords do not match. * @warning * always use this test, as platform-specific variances may meet this * more than one error code */ #define APR_STATUS_IS_EMISMATCH(s) ((s) == APR_EMISMATCH) /** * The given lock was busy * @warning always use this test, as platform-specific variances may meet this * more than one error code */ #define APR_STATUS_IS_EBUSY(s) ((s) == APR_EBUSY) /** @} */ /** * @addtogroup APR_Error APR Error Values * @{ */ /* APR CANONICAL ERROR VALUES */ /** @see APR_STATUS_IS_EACCES */ #ifdef EACCES #define APR_EACCES EACCES #else #define APR_EACCES (APR_OS_START_CANONERR + 1) #endif /** @see APR_STATUS_IS_EXIST */ #ifdef EEXIST #define APR_EEXIST EEXIST #else #define APR_EEXIST (APR_OS_START_CANONERR + 2) #endif /** @see APR_STATUS_IS_ENAMETOOLONG */ #ifdef ENAMETOOLONG #define APR_ENAMETOOLONG ENAMETOOLONG #else #define APR_ENAMETOOLONG (APR_OS_START_CANONERR + 3) #endif /** @see APR_STATUS_IS_ENOENT */ #ifdef ENOENT #define APR_ENOENT ENOENT #else #define APR_ENOENT (APR_OS_START_CANONERR + 4) #endif /** @see APR_STATUS_IS_ENOTDIR */ #ifdef ENOTDIR #define APR_ENOTDIR ENOTDIR #else #define APR_ENOTDIR (APR_OS_START_CANONERR + 5) #endif /** @see APR_STATUS_IS_ENOSPC */ #ifdef ENOSPC #define APR_ENOSPC ENOSPC #else #define APR_ENOSPC (APR_OS_START_CANONERR + 6) #endif /** @see APR_STATUS_IS_ENOMEM */ #ifdef ENOMEM #define APR_ENOMEM ENOMEM #else #define APR_ENOMEM (APR_OS_START_CANONERR + 7) #endif /** @see APR_STATUS_IS_EMFILE */ #ifdef EMFILE #define APR_EMFILE EMFILE #else #define APR_EMFILE (APR_OS_START_CANONERR + 8) #endif /** @see APR_STATUS_IS_ENFILE */ #ifdef ENFILE #define APR_ENFILE ENFILE #else #define APR_ENFILE (APR_OS_START_CANONERR + 9) #endif /** @see APR_STATUS_IS_EBADF */ #ifdef EBADF #define APR_EBADF EBADF #else #define APR_EBADF (APR_OS_START_CANONERR + 10) #endif /** @see APR_STATUS_IS_EINVAL */ #ifdef EINVAL #define APR_EINVAL EINVAL #else #define APR_EINVAL (APR_OS_START_CANONERR + 11) #endif /** @see APR_STATUS_IS_ESPIPE */ #ifdef ESPIPE #define APR_ESPIPE ESPIPE #else #define APR_ESPIPE (APR_OS_START_CANONERR + 12) #endif /** * @see APR_STATUS_IS_EAGAIN * @warning use APR_STATUS_IS_EAGAIN instead of just testing this value */ #ifdef EAGAIN #define APR_EAGAIN EAGAIN #elif defined(EWOULDBLOCK) #define APR_EAGAIN EWOULDBLOCK #else #define APR_EAGAIN (APR_OS_START_CANONERR + 13) #endif /** @see APR_STATUS_IS_EINTR */ #ifdef EINTR #define APR_EINTR EINTR #else #define APR_EINTR (APR_OS_START_CANONERR + 14) #endif /** @see APR_STATUS_IS_ENOTSOCK */ #ifdef ENOTSOCK #define APR_ENOTSOCK ENOTSOCK #else #define APR_ENOTSOCK (APR_OS_START_CANONERR + 15) #endif /** @see APR_STATUS_IS_ECONNREFUSED */ #ifdef ECONNREFUSED #define APR_ECONNREFUSED ECONNREFUSED #else #define APR_ECONNREFUSED (APR_OS_START_CANONERR + 16) #endif /** @see APR_STATUS_IS_EINPROGRESS */ #ifdef EINPROGRESS #define APR_EINPROGRESS EINPROGRESS #else #define APR_EINPROGRESS (APR_OS_START_CANONERR + 17) #endif /** * @see APR_STATUS_IS_ECONNABORTED * @warning use APR_STATUS_IS_ECONNABORTED instead of just testing this value */ #ifdef ECONNABORTED #define APR_ECONNABORTED ECONNABORTED #else #define APR_ECONNABORTED (APR_OS_START_CANONERR + 18) #endif /** @see APR_STATUS_IS_ECONNRESET */ #ifdef ECONNRESET #define APR_ECONNRESET ECONNRESET #else #define APR_ECONNRESET (APR_OS_START_CANONERR + 19) #endif /** @see APR_STATUS_IS_ETIMEDOUT * @deprecated */ #ifdef ETIMEDOUT #define APR_ETIMEDOUT ETIMEDOUT #else #define APR_ETIMEDOUT (APR_OS_START_CANONERR + 20) #endif /** @see APR_STATUS_IS_EHOSTUNREACH */ #ifdef EHOSTUNREACH #define APR_EHOSTUNREACH EHOSTUNREACH #else #define APR_EHOSTUNREACH (APR_OS_START_CANONERR + 21) #endif /** @see APR_STATUS_IS_ENETUNREACH */ #ifdef ENETUNREACH #define APR_ENETUNREACH ENETUNREACH #else #define APR_ENETUNREACH (APR_OS_START_CANONERR + 22) #endif /** @see APR_STATUS_IS_EFTYPE */ #ifdef EFTYPE #define APR_EFTYPE EFTYPE #else #define APR_EFTYPE (APR_OS_START_CANONERR + 23) #endif /** @see APR_STATUS_IS_EPIPE */ #ifdef EPIPE #define APR_EPIPE EPIPE #else #define APR_EPIPE (APR_OS_START_CANONERR + 24) #endif /** @see APR_STATUS_IS_EXDEV */ #ifdef EXDEV #define APR_EXDEV EXDEV #else #define APR_EXDEV (APR_OS_START_CANONERR + 25) #endif /** @see APR_STATUS_IS_ENOTEMPTY */ #ifdef ENOTEMPTY #define APR_ENOTEMPTY ENOTEMPTY #else #define APR_ENOTEMPTY (APR_OS_START_CANONERR + 26) #endif /** @} */ #if defined(OS2) && !defined(DOXYGEN) #define APR_FROM_OS_ERROR(e) (e == 0 ? APR_SUCCESS : e + APR_OS_START_SYSERR) #define APR_TO_OS_ERROR(e) (e == 0 ? APR_SUCCESS : e - APR_OS_START_SYSERR) #define INCL_DOSERRORS #define INCL_DOS /* Leave these undefined. * OS2 doesn't rely on the errno concept. * The API calls always return a result codes which * should be filtered through APR_FROM_OS_ERROR(). * * #define apr_get_os_error() (APR_FROM_OS_ERROR(GetLastError())) * #define apr_set_os_error(e) (SetLastError(APR_TO_OS_ERROR(e))) */ /* A special case, only socket calls require this; */ #define apr_get_netos_error() (APR_FROM_OS_ERROR(errno)) #define apr_set_netos_error(e) (errno = APR_TO_OS_ERROR(e)) /* And this needs to be greped away for good: */ #define APR_OS2_STATUS(e) (APR_FROM_OS_ERROR(e)) /* These can't sit in a private header, so in spite of the extra size, * they need to be made available here. */ #define SOCBASEERR 10000 #define SOCEPERM (SOCBASEERR+1) /* Not owner */ #define SOCESRCH (SOCBASEERR+3) /* No such process */ #define SOCEINTR (SOCBASEERR+4) /* Interrupted system call */ #define SOCENXIO (SOCBASEERR+6) /* No such device or address */ #define SOCEBADF (SOCBASEERR+9) /* Bad file number */ #define SOCEACCES (SOCBASEERR+13) /* Permission denied */ #define SOCEFAULT (SOCBASEERR+14) /* Bad address */ #define SOCEINVAL (SOCBASEERR+22) /* Invalid argument */ #define SOCEMFILE (SOCBASEERR+24) /* Too many open files */ #define SOCEPIPE (SOCBASEERR+32) /* Broken pipe */ #define SOCEOS2ERR (SOCBASEERR+100) /* OS/2 Error */ #define SOCEWOULDBLOCK (SOCBASEERR+35) /* Operation would block */ #define SOCEINPROGRESS (SOCBASEERR+36) /* Operation now in progress */ #define SOCEALREADY (SOCBASEERR+37) /* Operation already in progress */ #define SOCENOTSOCK (SOCBASEERR+38) /* Socket operation on non-socket */ #define SOCEDESTADDRREQ (SOCBASEERR+39) /* Destination address required */ #define SOCEMSGSIZE (SOCBASEERR+40) /* Message too long */ #define SOCEPROTOTYPE (SOCBASEERR+41) /* Protocol wrong type for socket */ #define SOCENOPROTOOPT (SOCBASEERR+42) /* Protocol not available */ #define SOCEPROTONOSUPPORT (SOCBASEERR+43) /* Protocol not supported */ #define SOCESOCKTNOSUPPORT (SOCBASEERR+44) /* Socket type not supported */ #define SOCEOPNOTSUPP (SOCBASEERR+45) /* Operation not supported on socket */ #define SOCEPFNOSUPPORT (SOCBASEERR+46) /* Protocol family not supported */ #define SOCEAFNOSUPPORT (SOCBASEERR+47) /* Address family not supported by protocol family */ #define SOCEADDRINUSE (SOCBASEERR+48) /* Address already in use */ #define SOCEADDRNOTAVAIL (SOCBASEERR+49) /* Can't assign requested address */ #define SOCENETDOWN (SOCBASEERR+50) /* Network is down */ #define SOCENETUNREACH (SOCBASEERR+51) /* Network is unreachable */ #define SOCENETRESET (SOCBASEERR+52) /* Network dropped connection on reset */ #define SOCECONNABORTED (SOCBASEERR+53) /* Software caused connection abort */ #define SOCECONNRESET (SOCBASEERR+54) /* Connection reset by peer */ #define SOCENOBUFS (SOCBASEERR+55) /* No buffer space available */ #define SOCEISCONN (SOCBASEERR+56) /* Socket is already connected */ #define SOCENOTCONN (SOCBASEERR+57) /* Socket is not connected */ #define SOCESHUTDOWN (SOCBASEERR+58) /* Can't send after socket shutdown */ #define SOCETOOMANYREFS (SOCBASEERR+59) /* Too many references: can't splice */ #define SOCETIMEDOUT (SOCBASEERR+60) /* Connection timed out */ #define SOCECONNREFUSED (SOCBASEERR+61) /* Connection refused */ #define SOCELOOP (SOCBASEERR+62) /* Too many levels of symbolic links */ #define SOCENAMETOOLONG (SOCBASEERR+63) /* File name too long */ #define SOCEHOSTDOWN (SOCBASEERR+64) /* Host is down */ #define SOCEHOSTUNREACH (SOCBASEERR+65) /* No route to host */ #define SOCENOTEMPTY (SOCBASEERR+66) /* Directory not empty */ /* APR CANONICAL ERROR TESTS */ #define APR_STATUS_IS_EACCES(s) ((s) == APR_EACCES \ || (s) == APR_OS_START_SYSERR + ERROR_ACCESS_DENIED \ || (s) == APR_OS_START_SYSERR + ERROR_SHARING_VIOLATION) #define APR_STATUS_IS_EEXIST(s) ((s) == APR_EEXIST \ || (s) == APR_OS_START_SYSERR + ERROR_OPEN_FAILED \ || (s) == APR_OS_START_SYSERR + ERROR_FILE_EXISTS \ || (s) == APR_OS_START_SYSERR + ERROR_ALREADY_EXISTS \ || (s) == APR_OS_START_SYSERR + ERROR_ACCESS_DENIED) #define APR_STATUS_IS_ENAMETOOLONG(s) ((s) == APR_ENAMETOOLONG \ || (s) == APR_OS_START_SYSERR + ERROR_FILENAME_EXCED_RANGE \ || (s) == APR_OS_START_SYSERR + SOCENAMETOOLONG) #define APR_STATUS_IS_ENOENT(s) ((s) == APR_ENOENT \ || (s) == APR_OS_START_SYSERR + ERROR_FILE_NOT_FOUND \ || (s) == APR_OS_START_SYSERR + ERROR_PATH_NOT_FOUND \ || (s) == APR_OS_START_SYSERR + ERROR_NO_MORE_FILES \ || (s) == APR_OS_START_SYSERR + ERROR_OPEN_FAILED) #define APR_STATUS_IS_ENOTDIR(s) ((s) == APR_ENOTDIR) #define APR_STATUS_IS_ENOSPC(s) ((s) == APR_ENOSPC \ || (s) == APR_OS_START_SYSERR + ERROR_DISK_FULL) #define APR_STATUS_IS_ENOMEM(s) ((s) == APR_ENOMEM) #define APR_STATUS_IS_EMFILE(s) ((s) == APR_EMFILE \ || (s) == APR_OS_START_SYSERR + ERROR_TOO_MANY_OPEN_FILES) #define APR_STATUS_IS_ENFILE(s) ((s) == APR_ENFILE) #define APR_STATUS_IS_EBADF(s) ((s) == APR_EBADF \ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_HANDLE) #define APR_STATUS_IS_EINVAL(s) ((s) == APR_EINVAL \ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_PARAMETER \ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_FUNCTION) #define APR_STATUS_IS_ESPIPE(s) ((s) == APR_ESPIPE \ || (s) == APR_OS_START_SYSERR + ERROR_NEGATIVE_SEEK) #define APR_STATUS_IS_EAGAIN(s) ((s) == APR_EAGAIN \ || (s) == APR_OS_START_SYSERR + ERROR_NO_DATA \ || (s) == APR_OS_START_SYSERR + SOCEWOULDBLOCK \ || (s) == APR_OS_START_SYSERR + ERROR_LOCK_VIOLATION) #define APR_STATUS_IS_EINTR(s) ((s) == APR_EINTR \ || (s) == APR_OS_START_SYSERR + SOCEINTR) #define APR_STATUS_IS_ENOTSOCK(s) ((s) == APR_ENOTSOCK \ || (s) == APR_OS_START_SYSERR + SOCENOTSOCK) #define APR_STATUS_IS_ECONNREFUSED(s) ((s) == APR_ECONNREFUSED \ || (s) == APR_OS_START_SYSERR + SOCECONNREFUSED) #define APR_STATUS_IS_EINPROGRESS(s) ((s) == APR_EINPROGRESS \ || (s) == APR_OS_START_SYSERR + SOCEINPROGRESS) #define APR_STATUS_IS_ECONNABORTED(s) ((s) == APR_ECONNABORTED \ || (s) == APR_OS_START_SYSERR + SOCECONNABORTED) #define APR_STATUS_IS_ECONNRESET(s) ((s) == APR_ECONNRESET \ || (s) == APR_OS_START_SYSERR + SOCECONNRESET) /* XXX deprecated */ #define APR_STATUS_IS_ETIMEDOUT(s) ((s) == APR_ETIMEDOUT \ || (s) == APR_OS_START_SYSERR + SOCETIMEDOUT) #undef APR_STATUS_IS_TIMEUP #define APR_STATUS_IS_TIMEUP(s) ((s) == APR_TIMEUP \ || (s) == APR_OS_START_SYSERR + SOCETIMEDOUT) #define APR_STATUS_IS_EHOSTUNREACH(s) ((s) == APR_EHOSTUNREACH \ || (s) == APR_OS_START_SYSERR + SOCEHOSTUNREACH) #define APR_STATUS_IS_ENETUNREACH(s) ((s) == APR_ENETUNREACH \ || (s) == APR_OS_START_SYSERR + SOCENETUNREACH) #define APR_STATUS_IS_EFTYPE(s) ((s) == APR_EFTYPE) #define APR_STATUS_IS_EPIPE(s) ((s) == APR_EPIPE \ || (s) == APR_OS_START_SYSERR + ERROR_BROKEN_PIPE \ || (s) == APR_OS_START_SYSERR + SOCEPIPE) #define APR_STATUS_IS_EXDEV(s) ((s) == APR_EXDEV \ || (s) == APR_OS_START_SYSERR + ERROR_NOT_SAME_DEVICE) #define APR_STATUS_IS_ENOTEMPTY(s) ((s) == APR_ENOTEMPTY \ || (s) == APR_OS_START_SYSERR + ERROR_DIR_NOT_EMPTY \ || (s) == APR_OS_START_SYSERR + ERROR_ACCESS_DENIED) /* Sorry, too tired to wrap this up for OS2... feel free to fit the following into their best matches. { ERROR_NO_SIGNAL_SENT, ESRCH }, { SOCEALREADY, EALREADY }, { SOCEDESTADDRREQ, EDESTADDRREQ }, { SOCEMSGSIZE, EMSGSIZE }, { SOCEPROTOTYPE, EPROTOTYPE }, { SOCENOPROTOOPT, ENOPROTOOPT }, { SOCEPROTONOSUPPORT, EPROTONOSUPPORT }, { SOCESOCKTNOSUPPORT, ESOCKTNOSUPPORT }, { SOCEOPNOTSUPP, EOPNOTSUPP }, { SOCEPFNOSUPPORT, EPFNOSUPPORT }, { SOCEAFNOSUPPORT, EAFNOSUPPORT }, { SOCEADDRINUSE, EADDRINUSE }, { SOCEADDRNOTAVAIL, EADDRNOTAVAIL }, { SOCENETDOWN, ENETDOWN }, { SOCENETRESET, ENETRESET }, { SOCENOBUFS, ENOBUFS }, { SOCEISCONN, EISCONN }, { SOCENOTCONN, ENOTCONN }, { SOCESHUTDOWN, ESHUTDOWN }, { SOCETOOMANYREFS, ETOOMANYREFS }, { SOCELOOP, ELOOP }, { SOCEHOSTDOWN, EHOSTDOWN }, { SOCENOTEMPTY, ENOTEMPTY }, { SOCEPIPE, EPIPE } */ #elif defined(WIN32) && !defined(DOXYGEN) /* !defined(OS2) */ #define APR_FROM_OS_ERROR(e) (e == 0 ? APR_SUCCESS : e + APR_OS_START_SYSERR) #define APR_TO_OS_ERROR(e) (e == 0 ? APR_SUCCESS : e - APR_OS_START_SYSERR) #define apr_get_os_error() (APR_FROM_OS_ERROR(GetLastError())) #define apr_set_os_error(e) (SetLastError(APR_TO_OS_ERROR(e))) /* A special case, only socket calls require this: */ #define apr_get_netos_error() (APR_FROM_OS_ERROR(WSAGetLastError())) #define apr_set_netos_error(e) (WSASetLastError(APR_TO_OS_ERROR(e))) /* APR CANONICAL ERROR TESTS */ #define APR_STATUS_IS_EACCES(s) ((s) == APR_EACCES \ || (s) == APR_OS_START_SYSERR + ERROR_ACCESS_DENIED \ || (s) == APR_OS_START_SYSERR + ERROR_CANNOT_MAKE \ || (s) == APR_OS_START_SYSERR + ERROR_CURRENT_DIRECTORY \ || (s) == APR_OS_START_SYSERR + ERROR_DRIVE_LOCKED \ || (s) == APR_OS_START_SYSERR + ERROR_FAIL_I24 \ || (s) == APR_OS_START_SYSERR + ERROR_LOCK_VIOLATION \ || (s) == APR_OS_START_SYSERR + ERROR_LOCK_FAILED \ || (s) == APR_OS_START_SYSERR + ERROR_NOT_LOCKED \ || (s) == APR_OS_START_SYSERR + ERROR_NETWORK_ACCESS_DENIED \ || (s) == APR_OS_START_SYSERR + ERROR_SHARING_VIOLATION) #define APR_STATUS_IS_EEXIST(s) ((s) == APR_EEXIST \ || (s) == APR_OS_START_SYSERR + ERROR_FILE_EXISTS \ || (s) == APR_OS_START_SYSERR + ERROR_ALREADY_EXISTS) #define APR_STATUS_IS_ENAMETOOLONG(s) ((s) == APR_ENAMETOOLONG \ || (s) == APR_OS_START_SYSERR + ERROR_FILENAME_EXCED_RANGE \ || (s) == APR_OS_START_SYSERR + WSAENAMETOOLONG) #define APR_STATUS_IS_ENOENT(s) ((s) == APR_ENOENT \ || (s) == APR_OS_START_SYSERR + ERROR_FILE_NOT_FOUND \ || (s) == APR_OS_START_SYSERR + ERROR_PATH_NOT_FOUND \ || (s) == APR_OS_START_SYSERR + ERROR_OPEN_FAILED \ || (s) == APR_OS_START_SYSERR + ERROR_NO_MORE_FILES) #define APR_STATUS_IS_ENOTDIR(s) ((s) == APR_ENOTDIR \ || (s) == APR_OS_START_SYSERR + ERROR_PATH_NOT_FOUND \ || (s) == APR_OS_START_SYSERR + ERROR_BAD_NETPATH \ || (s) == APR_OS_START_SYSERR + ERROR_BAD_NET_NAME \ || (s) == APR_OS_START_SYSERR + ERROR_BAD_PATHNAME \ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_DRIVE) #define APR_STATUS_IS_ENOSPC(s) ((s) == APR_ENOSPC \ || (s) == APR_OS_START_SYSERR + ERROR_DISK_FULL) #define APR_STATUS_IS_ENOMEM(s) ((s) == APR_ENOMEM \ || (s) == APR_OS_START_SYSERR + ERROR_ARENA_TRASHED \ || (s) == APR_OS_START_SYSERR + ERROR_NOT_ENOUGH_MEMORY \ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_BLOCK \ || (s) == APR_OS_START_SYSERR + ERROR_NOT_ENOUGH_QUOTA \ || (s) == APR_OS_START_SYSERR + ERROR_OUTOFMEMORY) #define APR_STATUS_IS_EMFILE(s) ((s) == APR_EMFILE \ || (s) == APR_OS_START_SYSERR + ERROR_TOO_MANY_OPEN_FILES) #define APR_STATUS_IS_ENFILE(s) ((s) == APR_ENFILE) #define APR_STATUS_IS_EBADF(s) ((s) == APR_EBADF \ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_HANDLE \ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_TARGET_HANDLE) #define APR_STATUS_IS_EINVAL(s) ((s) == APR_EINVAL \ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_ACCESS \ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_DATA \ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_FUNCTION \ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_HANDLE \ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_PARAMETER \ || (s) == APR_OS_START_SYSERR + ERROR_NEGATIVE_SEEK) #define APR_STATUS_IS_ESPIPE(s) ((s) == APR_ESPIPE \ || (s) == APR_OS_START_SYSERR + ERROR_SEEK_ON_DEVICE \ || (s) == APR_OS_START_SYSERR + ERROR_NEGATIVE_SEEK) #define APR_STATUS_IS_EAGAIN(s) ((s) == APR_EAGAIN \ || (s) == APR_OS_START_SYSERR + ERROR_NO_DATA \ || (s) == APR_OS_START_SYSERR + ERROR_NO_PROC_SLOTS \ || (s) == APR_OS_START_SYSERR + ERROR_NESTING_NOT_ALLOWED \ || (s) == APR_OS_START_SYSERR + ERROR_MAX_THRDS_REACHED \ || (s) == APR_OS_START_SYSERR + ERROR_LOCK_VIOLATION \ || (s) == APR_OS_START_SYSERR + WSAEWOULDBLOCK) #define APR_STATUS_IS_EINTR(s) ((s) == APR_EINTR \ || (s) == APR_OS_START_SYSERR + WSAEINTR) #define APR_STATUS_IS_ENOTSOCK(s) ((s) == APR_ENOTSOCK \ || (s) == APR_OS_START_SYSERR + WSAENOTSOCK) #define APR_STATUS_IS_ECONNREFUSED(s) ((s) == APR_ECONNREFUSED \ || (s) == APR_OS_START_SYSERR + WSAECONNREFUSED) #define APR_STATUS_IS_EINPROGRESS(s) ((s) == APR_EINPROGRESS \ || (s) == APR_OS_START_SYSERR + WSAEINPROGRESS) #define APR_STATUS_IS_ECONNABORTED(s) ((s) == APR_ECONNABORTED \ || (s) == APR_OS_START_SYSERR + WSAECONNABORTED) #define APR_STATUS_IS_ECONNRESET(s) ((s) == APR_ECONNRESET \ || (s) == APR_OS_START_SYSERR + ERROR_NETNAME_DELETED \ || (s) == APR_OS_START_SYSERR + WSAECONNRESET) /* XXX deprecated */ #define APR_STATUS_IS_ETIMEDOUT(s) ((s) == APR_ETIMEDOUT \ || (s) == APR_OS_START_SYSERR + WSAETIMEDOUT \ || (s) == APR_OS_START_SYSERR + WAIT_TIMEOUT) #undef APR_STATUS_IS_TIMEUP #define APR_STATUS_IS_TIMEUP(s) ((s) == APR_TIMEUP \ || (s) == APR_OS_START_SYSERR + WSAETIMEDOUT \ || (s) == APR_OS_START_SYSERR + WAIT_TIMEOUT) #define APR_STATUS_IS_EHOSTUNREACH(s) ((s) == APR_EHOSTUNREACH \ || (s) == APR_OS_START_SYSERR + WSAEHOSTUNREACH) #define APR_STATUS_IS_ENETUNREACH(s) ((s) == APR_ENETUNREACH \ || (s) == APR_OS_START_SYSERR + WSAENETUNREACH) #define APR_STATUS_IS_EFTYPE(s) ((s) == APR_EFTYPE \ || (s) == APR_OS_START_SYSERR + ERROR_EXE_MACHINE_TYPE_MISMATCH \ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_DLL \ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_MODULETYPE \ || (s) == APR_OS_START_SYSERR + ERROR_BAD_EXE_FORMAT \ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_EXE_SIGNATURE \ || (s) == APR_OS_START_SYSERR + ERROR_FILE_CORRUPT \ || (s) == APR_OS_START_SYSERR + ERROR_BAD_FORMAT) #define APR_STATUS_IS_EPIPE(s) ((s) == APR_EPIPE \ || (s) == APR_OS_START_SYSERR + ERROR_BROKEN_PIPE) #define APR_STATUS_IS_EXDEV(s) ((s) == APR_EXDEV \ || (s) == APR_OS_START_SYSERR + ERROR_NOT_SAME_DEVICE) #define APR_STATUS_IS_ENOTEMPTY(s) ((s) == APR_ENOTEMPTY \ || (s) == APR_OS_START_SYSERR + ERROR_DIR_NOT_EMPTY) #elif defined(NETWARE) && defined(USE_WINSOCK) && !defined(DOXYGEN) /* !defined(OS2) && !defined(WIN32) */ #define APR_FROM_OS_ERROR(e) (e == 0 ? APR_SUCCESS : e + APR_OS_START_SYSERR) #define APR_TO_OS_ERROR(e) (e == 0 ? APR_SUCCESS : e - APR_OS_START_SYSERR) #define apr_get_os_error() (errno) #define apr_set_os_error(e) (errno = (e)) /* A special case, only socket calls require this: */ #define apr_get_netos_error() (APR_FROM_OS_ERROR(WSAGetLastError())) #define apr_set_netos_error(e) (WSASetLastError(APR_TO_OS_ERROR(e))) /* APR CANONICAL ERROR TESTS */ #define APR_STATUS_IS_EACCES(s) ((s) == APR_EACCES) #define APR_STATUS_IS_EEXIST(s) ((s) == APR_EEXIST) #define APR_STATUS_IS_ENAMETOOLONG(s) ((s) == APR_ENAMETOOLONG) #define APR_STATUS_IS_ENOENT(s) ((s) == APR_ENOENT) #define APR_STATUS_IS_ENOTDIR(s) ((s) == APR_ENOTDIR) #define APR_STATUS_IS_ENOSPC(s) ((s) == APR_ENOSPC) #define APR_STATUS_IS_ENOMEM(s) ((s) == APR_ENOMEM) #define APR_STATUS_IS_EMFILE(s) ((s) == APR_EMFILE) #define APR_STATUS_IS_ENFILE(s) ((s) == APR_ENFILE) #define APR_STATUS_IS_EBADF(s) ((s) == APR_EBADF) #define APR_STATUS_IS_EINVAL(s) ((s) == APR_EINVAL) #define APR_STATUS_IS_ESPIPE(s) ((s) == APR_ESPIPE) #define APR_STATUS_IS_EAGAIN(s) ((s) == APR_EAGAIN \ || (s) == EWOULDBLOCK \ || (s) == APR_OS_START_SYSERR + WSAEWOULDBLOCK) #define APR_STATUS_IS_EINTR(s) ((s) == APR_EINTR \ || (s) == APR_OS_START_SYSERR + WSAEINTR) #define APR_STATUS_IS_ENOTSOCK(s) ((s) == APR_ENOTSOCK \ || (s) == APR_OS_START_SYSERR + WSAENOTSOCK) #define APR_STATUS_IS_ECONNREFUSED(s) ((s) == APR_ECONNREFUSED \ || (s) == APR_OS_START_SYSERR + WSAECONNREFUSED) #define APR_STATUS_IS_EINPROGRESS(s) ((s) == APR_EINPROGRESS \ || (s) == APR_OS_START_SYSERR + WSAEINPROGRESS) #define APR_STATUS_IS_ECONNABORTED(s) ((s) == APR_ECONNABORTED \ || (s) == APR_OS_START_SYSERR + WSAECONNABORTED) #define APR_STATUS_IS_ECONNRESET(s) ((s) == APR_ECONNRESET \ || (s) == APR_OS_START_SYSERR + WSAECONNRESET) /* XXX deprecated */ #define APR_STATUS_IS_ETIMEDOUT(s) ((s) == APR_ETIMEDOUT \ || (s) == APR_OS_START_SYSERR + WSAETIMEDOUT \ || (s) == APR_OS_START_SYSERR + WAIT_TIMEOUT) #undef APR_STATUS_IS_TIMEUP #define APR_STATUS_IS_TIMEUP(s) ((s) == APR_TIMEUP \ || (s) == APR_OS_START_SYSERR + WSAETIMEDOUT \ || (s) == APR_OS_START_SYSERR + WAIT_TIMEOUT) #define APR_STATUS_IS_EHOSTUNREACH(s) ((s) == APR_EHOSTUNREACH \ || (s) == APR_OS_START_SYSERR + WSAEHOSTUNREACH) #define APR_STATUS_IS_ENETUNREACH(s) ((s) == APR_ENETUNREACH \ || (s) == APR_OS_START_SYSERR + WSAENETUNREACH) #define APR_STATUS_IS_ENETDOWN(s) ((s) == APR_OS_START_SYSERR + WSAENETDOWN) #define APR_STATUS_IS_EFTYPE(s) ((s) == APR_EFTYPE) #define APR_STATUS_IS_EPIPE(s) ((s) == APR_EPIPE) #define APR_STATUS_IS_EXDEV(s) ((s) == APR_EXDEV) #define APR_STATUS_IS_ENOTEMPTY(s) ((s) == APR_ENOTEMPTY) #else /* !defined(NETWARE) && !defined(OS2) && !defined(WIN32) */ /* * os error codes are clib error codes */ #define APR_FROM_OS_ERROR(e) (e) #define APR_TO_OS_ERROR(e) (e) #define apr_get_os_error() (errno) #define apr_set_os_error(e) (errno = (e)) /* A special case, only socket calls require this: */ #define apr_get_netos_error() (errno) #define apr_set_netos_error(e) (errno = (e)) /** * @addtogroup APR_STATUS_IS * @{ */ /** permission denied */ #define APR_STATUS_IS_EACCES(s) ((s) == APR_EACCES) /** file exists */ #define APR_STATUS_IS_EEXIST(s) ((s) == APR_EEXIST) /** path name is too long */ #define APR_STATUS_IS_ENAMETOOLONG(s) ((s) == APR_ENAMETOOLONG) /** * no such file or directory * @remark * EMVSCATLG can be returned by the automounter on z/OS for * paths which do not exist. */ #ifdef EMVSCATLG #define APR_STATUS_IS_ENOENT(s) ((s) == APR_ENOENT \ || (s) == EMVSCATLG) #else #define APR_STATUS_IS_ENOENT(s) ((s) == APR_ENOENT) #endif /** not a directory */ #define APR_STATUS_IS_ENOTDIR(s) ((s) == APR_ENOTDIR) /** no space left on device */ #ifdef EDQUOT #define APR_STATUS_IS_ENOSPC(s) ((s) == APR_ENOSPC \ || (s) == EDQUOT) #else #define APR_STATUS_IS_ENOSPC(s) ((s) == APR_ENOSPC) #endif /** not enough memory */ #define APR_STATUS_IS_ENOMEM(s) ((s) == APR_ENOMEM) /** too many open files */ #define APR_STATUS_IS_EMFILE(s) ((s) == APR_EMFILE) /** file table overflow */ #define APR_STATUS_IS_ENFILE(s) ((s) == APR_ENFILE) /** bad file # */ #define APR_STATUS_IS_EBADF(s) ((s) == APR_EBADF) /** invalid argument */ #define APR_STATUS_IS_EINVAL(s) ((s) == APR_EINVAL) /** illegal seek */ #define APR_STATUS_IS_ESPIPE(s) ((s) == APR_ESPIPE) /** operation would block */ #if !defined(EWOULDBLOCK) || !defined(EAGAIN) #define APR_STATUS_IS_EAGAIN(s) ((s) == APR_EAGAIN) #elif (EWOULDBLOCK == EAGAIN) #define APR_STATUS_IS_EAGAIN(s) ((s) == APR_EAGAIN) #else #define APR_STATUS_IS_EAGAIN(s) ((s) == APR_EAGAIN \ || (s) == EWOULDBLOCK) #endif /** interrupted system call */ #define APR_STATUS_IS_EINTR(s) ((s) == APR_EINTR) /** socket operation on a non-socket */ #define APR_STATUS_IS_ENOTSOCK(s) ((s) == APR_ENOTSOCK) /** Connection Refused */ #define APR_STATUS_IS_ECONNREFUSED(s) ((s) == APR_ECONNREFUSED) /** operation now in progress */ #define APR_STATUS_IS_EINPROGRESS(s) ((s) == APR_EINPROGRESS) /** * Software caused connection abort * @remark * EPROTO on certain older kernels really means ECONNABORTED, so we need to * ignore it for them. See discussion in new-httpd archives nh.9701 & nh.9603 * * There is potentially a bug in Solaris 2.x x<6, and other boxes that * implement tcp sockets in userland (i.e. on top of STREAMS). On these * systems, EPROTO can actually result in a fatal loop. See PR#981 for * example. It's hard to handle both uses of EPROTO. */ #ifdef EPROTO #define APR_STATUS_IS_ECONNABORTED(s) ((s) == APR_ECONNABORTED \ || (s) == EPROTO) #else #define APR_STATUS_IS_ECONNABORTED(s) ((s) == APR_ECONNABORTED) #endif /** Connection Reset by peer */ #define APR_STATUS_IS_ECONNRESET(s) ((s) == APR_ECONNRESET) /** Operation timed out * @deprecated */ #define APR_STATUS_IS_ETIMEDOUT(s) ((s) == APR_ETIMEDOUT) /** no route to host */ #define APR_STATUS_IS_EHOSTUNREACH(s) ((s) == APR_EHOSTUNREACH) /** network is unreachable */ #define APR_STATUS_IS_ENETUNREACH(s) ((s) == APR_ENETUNREACH) /** inappropiate file type or format */ #define APR_STATUS_IS_EFTYPE(s) ((s) == APR_EFTYPE) /** broken pipe */ #define APR_STATUS_IS_EPIPE(s) ((s) == APR_EPIPE) /** cross device link */ #define APR_STATUS_IS_EXDEV(s) ((s) == APR_EXDEV) /** Directory Not Empty */ #define APR_STATUS_IS_ENOTEMPTY(s) ((s) == APR_ENOTEMPTY || \ (s) == APR_EEXIST) /** @} */ #endif /* !defined(NETWARE) && !defined(OS2) && !defined(WIN32) */ /** @} */ #ifdef __cplusplus } #endif #endif /* ! APR_ERRNO_H */
001-log4cxx
trunk/src/apr/include/apr_errno.h
C
asf20
51,421
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef APR_FILE_INFO_H #define APR_FILE_INFO_H /** * @file apr_file_info.h * @brief APR File Information */ #include "apr.h" #include "apr_user.h" #include "apr_pools.h" #include "apr_tables.h" #include "apr_time.h" #include "apr_errno.h" #if APR_HAVE_SYS_UIO_H #include <sys/uio.h> #endif #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /** * @defgroup apr_file_info File Information * @ingroup APR * @{ */ /* Many applications use the type member to determine the * existance of a file or initialization of the file info, * so the APR_NOFILE value must be distinct from APR_UNKFILE. */ /** apr_filetype_e values for the filetype member of the * apr_file_info_t structure * @warning: Not all of the filetypes below can be determined. * For example, a given platform might not correctly report * a socket descriptor as APR_SOCK if that type isn't * well-identified on that platform. In such cases where * a filetype exists but cannot be described by the recognized * flags below, the filetype will be APR_UNKFILE. If the * filetype member is not determined, the type will be APR_NOFILE. */ typedef enum { APR_NOFILE = 0, /**< no file type determined */ APR_REG, /**< a regular file */ APR_DIR, /**< a directory */ APR_CHR, /**< a character device */ APR_BLK, /**< a block device */ APR_PIPE, /**< a FIFO / pipe */ APR_LNK, /**< a symbolic link */ APR_SOCK, /**< a [unix domain] socket */ APR_UNKFILE = 127 /**< a file of some other unknown type */ } apr_filetype_e; /** * @defgroup apr_file_permissions File Permissions flags * @{ */ #define APR_FPROT_USETID 0x8000 /**< Set user id */ #define APR_FPROT_UREAD 0x0400 /**< Read by user */ #define APR_FPROT_UWRITE 0x0200 /**< Write by user */ #define APR_FPROT_UEXECUTE 0x0100 /**< Execute by user */ #define APR_FPROT_GSETID 0x4000 /**< Set group id */ #define APR_FPROT_GREAD 0x0040 /**< Read by group */ #define APR_FPROT_GWRITE 0x0020 /**< Write by group */ #define APR_FPROT_GEXECUTE 0x0010 /**< Execute by group */ #define APR_FPROT_WSTICKY 0x2000 /**< Sticky bit */ #define APR_FPROT_WREAD 0x0004 /**< Read by others */ #define APR_FPROT_WWRITE 0x0002 /**< Write by others */ #define APR_FPROT_WEXECUTE 0x0001 /**< Execute by others */ #define APR_FPROT_OS_DEFAULT 0x0FFF /**< use OS's default permissions */ /* additional permission flags for apr_file_copy and apr_file_append */ #define APR_FPROT_FILE_SOURCE_PERMS 0x1000 /**< Copy source file's permissions */ /* backcompat */ #define APR_USETID APR_FPROT_USETID /**< @deprecated @see APR_FPROT_USETID */ #define APR_UREAD APR_FPROT_UREAD /**< @deprecated @see APR_FPROT_UREAD */ #define APR_UWRITE APR_FPROT_UWRITE /**< @deprecated @see APR_FPROT_UWRITE */ #define APR_UEXECUTE APR_FPROT_UEXECUTE /**< @deprecated @see APR_FPROT_UEXECUTE */ #define APR_GSETID APR_FPROT_GSETID /**< @deprecated @see APR_FPROT_GSETID */ #define APR_GREAD APR_FPROT_GREAD /**< @deprecated @see APR_FPROT_GREAD */ #define APR_GWRITE APR_FPROT_GWRITE /**< @deprecated @see APR_FPROT_GWRITE */ #define APR_GEXECUTE APR_FPROT_GEXECUTE /**< @deprecated @see APR_FPROT_GEXECUTE */ #define APR_WSTICKY APR_FPROT_WSTICKY /**< @deprecated @see APR_FPROT_WSTICKY */ #define APR_WREAD APR_FPROT_WREAD /**< @deprecated @see APR_FPROT_WREAD */ #define APR_WWRITE APR_FPROT_WWRITE /**< @deprecated @see APR_FPROT_WWRITE */ #define APR_WEXECUTE APR_FPROT_WEXECUTE /**< @deprecated @see APR_FPROT_WEXECUTE */ #define APR_OS_DEFAULT APR_FPROT_OS_DEFAULT /**< @deprecated @see APR_FPROT_OS_DEFAULT */ #define APR_FILE_SOURCE_PERMS APR_FPROT_FILE_SOURCE_PERMS /**< @deprecated @see APR_FPROT_FILE_SOURCE_PERMS */ /** @} */ /** * Structure for referencing directories. */ typedef struct apr_dir_t apr_dir_t; /** * Structure for determining file permissions. */ typedef apr_int32_t apr_fileperms_t; #if (defined WIN32) || (defined NETWARE) /** * Structure for determining the inode of the file. */ typedef apr_uint64_t apr_ino_t; /** * Structure for determining the device the file is on. */ typedef apr_uint32_t apr_dev_t; #else /** The inode of the file. */ typedef ino_t apr_ino_t; /** * Structure for determining the device the file is on. */ typedef dev_t apr_dev_t; #endif /** * @defgroup apr_file_stat Stat Functions * @{ */ /** file info structure */ typedef struct apr_finfo_t apr_finfo_t; #define APR_FINFO_LINK 0x00000001 /**< Stat the link not the file itself if it is a link */ #define APR_FINFO_MTIME 0x00000010 /**< Modification Time */ #define APR_FINFO_CTIME 0x00000020 /**< Creation or inode-changed time */ #define APR_FINFO_ATIME 0x00000040 /**< Access Time */ #define APR_FINFO_SIZE 0x00000100 /**< Size of the file */ #define APR_FINFO_CSIZE 0x00000200 /**< Storage size consumed by the file */ #define APR_FINFO_DEV 0x00001000 /**< Device */ #define APR_FINFO_INODE 0x00002000 /**< Inode */ #define APR_FINFO_NLINK 0x00004000 /**< Number of links */ #define APR_FINFO_TYPE 0x00008000 /**< Type */ #define APR_FINFO_USER 0x00010000 /**< User */ #define APR_FINFO_GROUP 0x00020000 /**< Group */ #define APR_FINFO_UPROT 0x00100000 /**< User protection bits */ #define APR_FINFO_GPROT 0x00200000 /**< Group protection bits */ #define APR_FINFO_WPROT 0x00400000 /**< World protection bits */ #define APR_FINFO_ICASE 0x01000000 /**< if dev is case insensitive */ #define APR_FINFO_NAME 0x02000000 /**< ->name in proper case */ #define APR_FINFO_MIN 0x00008170 /**< type, mtime, ctime, atime, size */ #define APR_FINFO_IDENT 0x00003000 /**< dev and inode */ #define APR_FINFO_OWNER 0x00030000 /**< user and group */ #define APR_FINFO_PROT 0x00700000 /**< all protections */ #define APR_FINFO_NORM 0x0073b170 /**< an atomic unix apr_stat() */ #define APR_FINFO_DIRENT 0x02000000 /**< an atomic unix apr_dir_read() */ /** * The file information structure. This is analogous to the POSIX * stat structure. */ struct apr_finfo_t { /** Allocates memory and closes lingering handles in the specified pool */ apr_pool_t *pool; /** The bitmask describing valid fields of this apr_finfo_t structure * including all available 'wanted' fields and potentially more */ apr_int32_t valid; /** The access permissions of the file. Mimics Unix access rights. */ apr_fileperms_t protection; /** The type of file. One of APR_REG, APR_DIR, APR_CHR, APR_BLK, APR_PIPE, * APR_LNK or APR_SOCK. If the type is undetermined, the value is APR_NOFILE. * If the type cannot be determined, the value is APR_UNKFILE. */ apr_filetype_e filetype; /** The user id that owns the file */ apr_uid_t user; /** The group id that owns the file */ apr_gid_t group; /** The inode of the file. */ apr_ino_t inode; /** The id of the device the file is on. */ apr_dev_t device; /** The number of hard links to the file. */ apr_int32_t nlink; /** The size of the file */ apr_off_t size; /** The storage size consumed by the file */ apr_off_t csize; /** The time the file was last accessed */ apr_time_t atime; /** The time the file was last modified */ apr_time_t mtime; /** The time the file was created, or the inode was last changed */ apr_time_t ctime; /** The pathname of the file (possibly unrooted) */ const char *fname; /** The file's name (no path) in filesystem case */ const char *name; /** The file's handle, if accessed (can be submitted to apr_duphandle) */ struct apr_file_t *filehand; }; /** * get the specified file's stats. The file is specified by filename, * instead of using a pre-opened file. * @param finfo Where to store the information about the file, which is * never touched if the call fails. * @param fname The name of the file to stat. * @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_ values * @param pool the pool to use to allocate the new file. * * @note If @c APR_INCOMPLETE is returned all the fields in @a finfo may * not be filled in, and you need to check the @c finfo->valid bitmask * to verify that what you're looking for is there. */ APR_DECLARE(apr_status_t) apr_stat(apr_finfo_t *finfo, const char *fname, apr_int32_t wanted, apr_pool_t *pool); /** @} */ /** * @defgroup apr_dir Directory Manipulation Functions * @{ */ /** * Open the specified directory. * @param new_dir The opened directory descriptor. * @param dirname The full path to the directory (use / on all systems) * @param pool The pool to use. */ APR_DECLARE(apr_status_t) apr_dir_open(apr_dir_t **new_dir, const char *dirname, apr_pool_t *pool); /** * close the specified directory. * @param thedir the directory descriptor to close. */ APR_DECLARE(apr_status_t) apr_dir_close(apr_dir_t *thedir); /** * Read the next entry from the specified directory. * @param finfo the file info structure and filled in by apr_dir_read * @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_ values * @param thedir the directory descriptor returned from apr_dir_open * @remark No ordering is guaranteed for the entries read. * * @note If @c APR_INCOMPLETE is returned all the fields in @a finfo may * not be filled in, and you need to check the @c finfo->valid bitmask * to verify that what you're looking for is there. */ APR_DECLARE(apr_status_t) apr_dir_read(apr_finfo_t *finfo, apr_int32_t wanted, apr_dir_t *thedir); /** * Rewind the directory to the first entry. * @param thedir the directory descriptor to rewind. */ APR_DECLARE(apr_status_t) apr_dir_rewind(apr_dir_t *thedir); /** @} */ /** * @defgroup apr_filepath Filepath Manipulation Functions * @{ */ /** Cause apr_filepath_merge to fail if addpath is above rootpath */ #define APR_FILEPATH_NOTABOVEROOT 0x01 /** internal: Only meaningful with APR_FILEPATH_NOTABOVEROOT */ #define APR_FILEPATH_SECUREROOTTEST 0x02 /** Cause apr_filepath_merge to fail if addpath is above rootpath, * even given a rootpath /foo/bar and an addpath ../bar/bash */ #define APR_FILEPATH_SECUREROOT 0x03 /** Fail apr_filepath_merge if the merged path is relative */ #define APR_FILEPATH_NOTRELATIVE 0x04 /** Fail apr_filepath_merge if the merged path is absolute */ #define APR_FILEPATH_NOTABSOLUTE 0x08 /** Return the file system's native path format (e.g. path delimiters * of ':' on MacOS9, '\' on Win32, etc.) */ #define APR_FILEPATH_NATIVE 0x10 /** Resolve the true case of existing directories and file elements * of addpath, (resolving any aliases on Win32) and append a proper * trailing slash if a directory */ #define APR_FILEPATH_TRUENAME 0x20 /** * Extract the rootpath from the given filepath * @param rootpath the root file path returned with APR_SUCCESS or APR_EINCOMPLETE * @param filepath the pathname to parse for its root component * @param flags the desired rules to apply, from * <PRE> * APR_FILEPATH_NATIVE Use native path seperators (e.g. '\' on Win32) * APR_FILEPATH_TRUENAME Tests that the root exists, and makes it proper * </PRE> * @param p the pool to allocate the new path string from * @remark on return, filepath points to the first non-root character in the * given filepath. In the simplest example, given a filepath of "/foo", * returns the rootpath of "/" and filepath points at "foo". This is far * more complex on other platforms, which will canonicalize the root form * to a consistant format, given the APR_FILEPATH_TRUENAME flag, and also * test for the validity of that root (e.g., that a drive d:/ or network * share //machine/foovol/). * The function returns APR_ERELATIVE if filepath isn't rooted (an * error), APR_EINCOMPLETE if the root path is ambigious (but potentially * legitimate, e.g. "/" on Windows is incomplete because it doesn't specify * the drive letter), or APR_EBADPATH if the root is simply invalid. * APR_SUCCESS is returned if filepath is an absolute path. */ APR_DECLARE(apr_status_t) apr_filepath_root(const char **rootpath, const char **filepath, apr_int32_t flags, apr_pool_t *p); /** * Merge additional file path onto the previously processed rootpath * @param newpath the merged paths returned * @param rootpath the root file path (NULL uses the current working path) * @param addpath the path to add to the root path * @param flags the desired APR_FILEPATH_ rules to apply when merging * @param p the pool to allocate the new path string from * @remark if the flag APR_FILEPATH_TRUENAME is given, and the addpath * contains wildcard characters ('*', '?') on platforms that don't support * such characters within filenames, the paths will be merged, but the * result code will be APR_EPATHWILD, and all further segments will not * reflect the true filenames including the wildcard and following segments. */ APR_DECLARE(apr_status_t) apr_filepath_merge(char **newpath, const char *rootpath, const char *addpath, apr_int32_t flags, apr_pool_t *p); /** * Split a search path into separate components * @param pathelts the returned components of the search path * @param liststr the search path (e.g., <tt>getenv("PATH")</tt>) * @param p the pool to allocate the array and path components from * @remark empty path componenta do not become part of @a pathelts. * @remark the path separator in @a liststr is system specific; * e.g., ':' on Unix, ';' on Windows, etc. */ APR_DECLARE(apr_status_t) apr_filepath_list_split(apr_array_header_t **pathelts, const char *liststr, apr_pool_t *p); /** * Merge a list of search path components into a single search path * @param liststr the returned search path; may be NULL if @a pathelts is empty * @param pathelts the components of the search path * @param p the pool to allocate the search path from * @remark emtpy strings in the source array are ignored. * @remark the path separator in @a liststr is system specific; * e.g., ':' on Unix, ';' on Windows, etc. */ APR_DECLARE(apr_status_t) apr_filepath_list_merge(char **liststr, apr_array_header_t *pathelts, apr_pool_t *p); /** * Return the default file path (for relative file names) * @param path the default path string returned * @param flags optional flag APR_FILEPATH_NATIVE to retrieve the * default file path in os-native format. * @param p the pool to allocate the default path string from */ APR_DECLARE(apr_status_t) apr_filepath_get(char **path, apr_int32_t flags, apr_pool_t *p); /** * Set the default file path (for relative file names) * @param path the default path returned * @param p the pool to allocate any working storage */ APR_DECLARE(apr_status_t) apr_filepath_set(const char *path, apr_pool_t *p); /** The FilePath character encoding is unknown */ #define APR_FILEPATH_ENCODING_UNKNOWN 0 /** The FilePath character encoding is locale-dependent */ #define APR_FILEPATH_ENCODING_LOCALE 1 /** The FilePath character encoding is UTF-8 */ #define APR_FILEPATH_ENCODING_UTF8 2 /** * Determine the encoding used internally by the FilePath functions * @param style points to a variable which receives the encoding style flag * @param p the pool to allocate any working storage * @remark Use @c apr_os_locale_encoding and/or @c apr_os_default_encoding * to get the name of the path encoding if it's not UTF-8. */ APR_DECLARE(apr_status_t) apr_filepath_encoding(int *style, apr_pool_t *p); /** @} */ /** @} */ #ifdef __cplusplus } #endif #endif /* ! APR_FILE_INFO_H */
001-log4cxx
trunk/src/apr/include/apr_file_info.h
C
asf20
17,564
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef APR_VERSION_H #define APR_VERSION_H /** * @file apr_version.h * @brief APR Versioning Interface * * APR's Version * * There are several different mechanisms for accessing the version. There * is a string form, and a set of numbers; in addition, there are constants * which can be compiled into your application, and you can query the library * being used for its actual version. * * Note that it is possible for an application to detect that it has been * compiled against a different version of APR by use of the compile-time * constants and the use of the run-time query function. * * APR version numbering follows the guidelines specified in: * * http://apr.apache.org/versioning.html */ /* The numeric compile-time version constants. These constants are the * authoritative version numbers for APR. */ /** major version * Major API changes that could cause compatibility problems for older * programs such as structure size changes. No binary compatibility is * possible across a change in the major version. */ #define APR_MAJOR_VERSION 1 /** minor version * Minor API changes that do not cause binary compatibility problems. * Reset to 0 when upgrading APR_MAJOR_VERSION */ #define APR_MINOR_VERSION 2 /** patch level * The Patch Level never includes API changes, simply bug fixes. * Reset to 0 when upgrading APR_MINOR_VERSION */ #define APR_PATCH_VERSION 8 /** * The symbol APR_IS_DEV_VERSION is only defined for internal, * "development" copies of APR. It is undefined for released versions * of APR. */ /* #define APR_IS_DEV_VERSION */ #if defined(APR_IS_DEV_VERSION) || defined(DOXYGEN) /** Internal: string form of the "is dev" flag */ #define APR_IS_DEV_STRING "-dev" #else #define APR_IS_DEV_STRING "" #endif /* APR_STRINGIFY is defined here, and also in apr_general.h, so wrap it */ #ifndef APR_STRINGIFY /** Properly quote a value as a string in the C preprocessor */ #define APR_STRINGIFY(n) APR_STRINGIFY_HELPER(n) /** Helper macro for APR_STRINGIFY */ #define APR_STRINGIFY_HELPER(n) #n #endif /** The formatted string of APR's version */ #define APR_VERSION_STRING \ APR_STRINGIFY(APR_MAJOR_VERSION) "." \ APR_STRINGIFY(APR_MINOR_VERSION) "." \ APR_STRINGIFY(APR_PATCH_VERSION) \ APR_IS_DEV_STRING /** An alternative formatted string of APR's version */ /* macro for Win32 .rc files using numeric csv representation */ #define APR_VERSION_STRING_CSV APR_MAJOR_VERSION ##, \ ##APR_MINOR_VERSION ##, \ ##APR_PATCH_VERSION #ifndef APR_VERSION_ONLY /* The C language API to access the version at run time, * as opposed to compile time. APR_VERSION_ONLY may be defined * externally when preprocessing apr_version.h to obtain strictly * the C Preprocessor macro declarations. */ #include "apr.h" #ifdef __cplusplus extern "C" { #endif /** * The numeric version information is broken out into fields within this * structure. */ typedef struct { int major; /**< major number */ int minor; /**< minor number */ int patch; /**< patch number */ int is_dev; /**< is development (1 or 0) */ } apr_version_t; /** * Return APR's version information information in a numeric form. * * @param pvsn Pointer to a version structure for returning the version * information. */ APR_DECLARE(void) apr_version(apr_version_t *pvsn); /** Return APR's version information as a string. */ APR_DECLARE(const char *) apr_version_string(void); #ifdef __cplusplus } #endif #endif /* ndef APR_VERSION_ONLY */ #endif /* ndef APR_VERSION_H */
001-log4cxx
trunk/src/apr/include/apr_version.h
C
asf20
4,468
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef APR_SIGNAL_H #define APR_SIGNAL_H /** * @file apr_signal.h * @brief APR Signal Handling */ #include "apr.h" #include "apr_pools.h" #if APR_HAVE_SIGNAL_H #include <signal.h> #endif #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /** * @defgroup apr_signal Handling * @ingroup APR * @{ */ #if APR_HAVE_SIGACTION || defined(DOXYGEN) #if defined(DARWIN) && !defined(__cplusplus) && !defined(_ANSI_SOURCE) /* work around Darwin header file bugs * http://www.opensource.apple.com/bugs/X/BSD%20Kernel/2657228.html */ #undef SIG_DFL #undef SIG_IGN #undef SIG_ERR #define SIG_DFL (void (*)(int))0 #define SIG_IGN (void (*)(int))1 #define SIG_ERR (void (*)(int))-1 #endif /** Function prototype for signal handlers */ typedef void apr_sigfunc_t(int); /** * Set the signal handler function for a given signal * @param signo The signal (eg... SIGWINCH) * @param func the function to get called */ APR_DECLARE(apr_sigfunc_t *) apr_signal(int signo, apr_sigfunc_t * func); #if defined(SIG_IGN) && !defined(SIG_ERR) #define SIG_ERR ((apr_sigfunc_t *) -1) #endif #else /* !APR_HAVE_SIGACTION */ #define apr_signal(a, b) signal(a, b) #endif /** * Get the description for a specific signal number * @param signum The signal number * @return The description of the signal */ APR_DECLARE(const char *) apr_signal_description_get(int signum); /** * APR-private function for initializing the signal package * @internal * @param pglobal The internal, global pool */ void apr_signal_init(apr_pool_t *pglobal); /** * Block the delivery of a particular signal * @param signum The signal number * @return status */ APR_DECLARE(apr_status_t) apr_signal_block(int signum); /** * Enable the delivery of a particular signal * @param signum The signal number * @return status */ APR_DECLARE(apr_status_t) apr_signal_unblock(int signum); /** @} */ #ifdef __cplusplus } #endif /* __cplusplus */ #endif /* APR_SIGNAL_H */
001-log4cxx
trunk/src/apr/include/apr_signal.h
C
asf20
2,756
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef DSO_H #define DSO_H #include "apr_private.h" #include "apr_general.h" #include "apr_pools.h" #include "apr_dso.h" #include "apr.h" #if APR_HAS_DSO struct apr_dso_handle_t { apr_pool_t *cont; void *handle; apr_status_t load_error; }; #endif #endif
001-log4cxx
trunk/src/apr/include/arch/win32/apr_arch_dso.h
C
asf20
1,084
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef PROC_MUTEX_H #define PROC_MUTEX_H #include "apr_proc_mutex.h" struct apr_proc_mutex_t { apr_pool_t *pool; HANDLE handle; const char *fname; }; #endif /* PROC_MUTEX_H */
001-log4cxx
trunk/src/apr/include/arch/win32/apr_arch_proc_mutex.h
C
asf20
994
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef MISC_H #define MISC_H #include "apr.h" #include "apr_portable.h" #include "apr_private.h" #include "apr_general.h" #include "apr_pools.h" #include "apr_getopt.h" #include "apr_thread_proc.h" #include "apr_file_io.h" #include "apr_errno.h" #include "apr_getopt.h" #if APR_HAVE_STDIO_H #include <stdio.h> #endif #if APR_HAVE_SIGNAL_H #include <signal.h> #endif #if APR_HAVE_PTHREAD_H #include <pthread.h> #endif /* ### create APR_HAVE_* macros for these? */ #if APR_HAVE_STDLIB_H #include <stdlib.h> #endif #if APR_HAVE_STRING_H #include <string.h> #endif struct apr_other_child_rec_t { apr_pool_t *p; struct apr_other_child_rec_t *next; apr_proc_t *proc; void (*maintenance) (int, void *, int); void *data; apr_os_file_t write_fd; }; #define WSAHighByte 2 #define WSALowByte 0 /* start.c and apr_app.c helpers and communication within misc.c * * They are not for public consumption, although apr_app_init_complete * must be an exported symbol to avoid reinitialization. */ extern int APR_DECLARE_DATA apr_app_init_complete; int apr_wastrtoastr(char const * const * *retarr, wchar_t const * const *arr, int args); /* Platform specific designation of run time os version. * Gaps allow for specific service pack levels that * export new kernel or winsock functions or behavior. */ typedef enum { APR_WIN_UNK = 0, APR_WIN_UNSUP = 1, APR_WIN_95 = 10, APR_WIN_95_B = 11, APR_WIN_95_OSR2 = 12, APR_WIN_98 = 14, APR_WIN_98_SE = 16, APR_WIN_ME = 18, APR_WIN_UNICODE = 20, /* Prior versions support only narrow chars */ APR_WIN_CE_3 = 23, /* CE is an odd beast, not supporting */ /* some pre-NT features, such as the */ APR_WIN_NT = 30, /* narrow charset APIs (fooA fns), while */ APR_WIN_NT_3_5 = 35, /* not supporting some NT-family features. */ APR_WIN_NT_3_51 = 36, APR_WIN_NT_4 = 40, APR_WIN_NT_4_SP2 = 42, APR_WIN_NT_4_SP3 = 43, APR_WIN_NT_4_SP4 = 44, APR_WIN_NT_4_SP5 = 45, APR_WIN_NT_4_SP6 = 46, APR_WIN_2000 = 50, APR_WIN_2000_SP1 = 51, APR_WIN_2000_SP2 = 52, APR_WIN_XP = 60, APR_WIN_XP_SP1 = 61, APR_WIN_XP_SP2 = 62, APR_WIN_2003 = 70 } apr_oslevel_e; extern APR_DECLARE_DATA apr_oslevel_e apr_os_level; apr_status_t apr_get_oslevel(apr_oslevel_e *); /* The APR_HAS_ANSI_FS symbol is PRIVATE, and internal to APR. * APR only supports char data for filenames. Like most applications, * characters >127 are essentially undefined. APR_HAS_UNICODE_FS lets * the application know that utf-8 is the encoding method of APR, and * only incidently hints that we have Wide OS calls. * * APR_HAS_ANSI_FS is simply an OS flag to tell us all calls must be * the unicode eqivilant. */ #if defined(_WIN32_WCE) || defined(WINNT) #define APR_HAS_ANSI_FS 0 #else #define APR_HAS_ANSI_FS 1 #endif /* IF_WIN_OS_IS_UNICODE / ELSE_WIN_OS_IS_ANSI help us keep the code trivial * where have runtime tests for unicode-ness, that aren't needed in any * build which supports only WINNT or WCE. */ #if APR_HAS_ANSI_FS && APR_HAS_UNICODE_FS #define IF_WIN_OS_IS_UNICODE if (apr_os_level >= APR_WIN_UNICODE) #define ELSE_WIN_OS_IS_ANSI else #else /* APR_HAS_UNICODE_FS */ #define IF_WIN_OS_IS_UNICODE #define ELSE_WIN_OS_IS_ANSI #endif /* WINNT */ typedef enum { DLL_WINBASEAPI = 0, // kernel32 From WinBase.h DLL_WINADVAPI = 1, // advapi32 From WinBase.h DLL_WINSOCKAPI = 2, // mswsock From WinSock.h DLL_WINSOCK2API = 3, // ws2_32 From WinSock2.h DLL_SHSTDAPI = 4, // shell32 From ShellAPI.h DLL_NTDLL = 5, // shell32 From our real kernel DLL_defined = 6 // must define as last idx_ + 1 } apr_dlltoken_e; FARPROC apr_load_dll_func(apr_dlltoken_e fnLib, char *fnName, int ordinal); /* The apr_load_dll_func call WILL fault if the function cannot be loaded */ #define APR_DECLARE_LATE_DLL_FUNC(lib, rettype, calltype, fn, ord, args, names) \ typedef rettype (calltype *apr_winapi_fpt_##fn) args; \ static apr_winapi_fpt_##fn apr_winapi_pfn_##fn = NULL; \ __inline rettype apr_winapi_##fn args \ { if (!apr_winapi_pfn_##fn) \ apr_winapi_pfn_##fn = (apr_winapi_fpt_##fn) \ apr_load_dll_func(lib, #fn, ord); \ return (*(apr_winapi_pfn_##fn)) names; }; \ /* Provide late bound declarations of every API function missing from * one or more supported releases of the Win32 API * * lib is the enumerated token from apr_dlltoken_e, and must correspond * to the string table entry in start.c used by the apr_load_dll_func(). * Token names (attempt to) follow Windows.h declarations prefixed by DLL_ * in order to facilitate comparison. Use the exact declaration syntax * and names from Windows.h to prevent ambigutity and bugs. * * rettype and calltype follow the original declaration in Windows.h * fn is the true function name - beware Ansi/Unicode #defined macros * ord is the ordinal within the library, use 0 if it varies between versions * args is the parameter list following the original declaration, in parens * names is the parameter list sans data types, enclosed in parens * * #undef/re#define the Ansi/Unicode generic name to abate confusion * In the case of non-text functions, simply #define the original name */ #if !defined(_WIN32_WCE) && !defined(WINNT) #ifdef GetFileAttributesExA #undef GetFileAttributesExA #endif APR_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, BOOL, WINAPI, GetFileAttributesExA, 0, ( IN LPCSTR lpFileName, IN GET_FILEEX_INFO_LEVELS fInfoLevelId, OUT LPVOID lpFileInformation), (lpFileName, fInfoLevelId, lpFileInformation)); #define GetFileAttributesExA apr_winapi_GetFileAttributesExA #undef GetFileAttributesEx #define GetFileAttributesEx apr_winapi_GetFileAttributesExA #ifdef GetFileAttributesExW #undef GetFileAttributesExW #endif APR_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, BOOL, WINAPI, GetFileAttributesExW, 0, ( IN LPCWSTR lpFileName, IN GET_FILEEX_INFO_LEVELS fInfoLevelId, OUT LPVOID lpFileInformation), (lpFileName, fInfoLevelId, lpFileInformation)); #define GetFileAttributesExW apr_winapi_GetFileAttributesExW APR_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, BOOL, WINAPI, CancelIo, 0, ( IN HANDLE hFile), (hFile)); #define CancelIo apr_winapi_CancelIo APR_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, BOOL, WINAPI, TryEnterCriticalSection, 0, ( LPCRITICAL_SECTION lpCriticalSection), (lpCriticalSection)); #define TryEnterCriticalSection apr_winapi_TryEnterCriticalSection APR_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, BOOL, WINAPI, SwitchToThread, 0, ( void), ()); #define SwitchToThread apr_winapi_SwitchToThread APR_DECLARE_LATE_DLL_FUNC(DLL_WINADVAPI, BOOL, WINAPI, GetEffectiveRightsFromAclW, 0, ( IN PACL pacl, IN PTRUSTEE_W pTrustee, OUT PACCESS_MASK pAccessRights), (pacl, pTrustee, pAccessRights)); #define GetEffectiveRightsFromAclW apr_winapi_GetEffectiveRightsFromAclW APR_DECLARE_LATE_DLL_FUNC(DLL_WINADVAPI, BOOL, WINAPI, GetNamedSecurityInfoW, 0, ( IN LPWSTR pObjectName, IN SE_OBJECT_TYPE ObjectType, IN SECURITY_INFORMATION SecurityInfo, OUT PSID *ppsidOwner, OUT PSID *ppsidGroup, OUT PACL *ppDacl, OUT PACL *ppSacl, OUT PSECURITY_DESCRIPTOR *ppSecurityDescriptor), (pObjectName, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor)); #define GetNamedSecurityInfoW apr_winapi_GetNamedSecurityInfoW APR_DECLARE_LATE_DLL_FUNC(DLL_WINADVAPI, BOOL, WINAPI, GetNamedSecurityInfoA, 0, ( IN LPSTR pObjectName, IN SE_OBJECT_TYPE ObjectType, IN SECURITY_INFORMATION SecurityInfo, OUT PSID *ppsidOwner, OUT PSID *ppsidGroup, OUT PACL *ppDacl, OUT PACL *ppSacl, OUT PSECURITY_DESCRIPTOR *ppSecurityDescriptor), (pObjectName, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor)); #define GetNamedSecurityInfoA apr_winapi_GetNamedSecurityInfoA #undef GetNamedSecurityInfo #define GetNamedSecurityInfo apr_winapi_GetNamedSecurityInfoA APR_DECLARE_LATE_DLL_FUNC(DLL_WINADVAPI, BOOL, WINAPI, GetSecurityInfo, 0, ( IN HANDLE handle, IN SE_OBJECT_TYPE ObjectType, IN SECURITY_INFORMATION SecurityInfo, OUT PSID *ppsidOwner, OUT PSID *ppsidGroup, OUT PACL *ppDacl, OUT PACL *ppSacl, OUT PSECURITY_DESCRIPTOR *ppSecurityDescriptor), (handle, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor)); #define GetSecurityInfo apr_winapi_GetSecurityInfo APR_DECLARE_LATE_DLL_FUNC(DLL_SHSTDAPI, LPWSTR *, WINAPI, CommandLineToArgvW, 0, ( LPCWSTR lpCmdLine, int *pNumArgs), (lpCmdLine, pNumArgs)); #define CommandLineToArgvW apr_winapi_CommandLineToArgvW #endif /* !defined(_WIN32_WCE) && !defined(WINNT) */ #if !defined(_WIN32_WCE) APR_DECLARE_LATE_DLL_FUNC(DLL_NTDLL, DWORD, WINAPI, NtQueryTimerResolution, 0, ( ULONG *pMaxRes, /* Minimum NS Resolution */ ULONG *pMinRes, /* Maximum NS Resolution */ ULONG *pCurRes), /* Current NS Resolution */ (pMaxRes, pMinRes, pCurRes)); #define QueryTimerResolution apr_winapi_NtQueryTimerResolution APR_DECLARE_LATE_DLL_FUNC(DLL_NTDLL, DWORD, WINAPI, NtSetTimerResolution, 0, ( ULONG ReqRes, /* Requested NS Clock Resolution */ BOOL Acquire, /* Aquire (1) or Release (0) our interest */ ULONG *pNewRes), /* The NS Clock Resolution granted */ (ReqRes, Acquire, pNewRes)); #define SetTimerResolution apr_winapi_NtSetTimerResolution /* ### These are ULONG_PTR values, but that's int32 for all we care * until the Win64 port is prepared. */ typedef struct PBI { DWORD ExitStatus; PVOID PebBaseAddress; ULONG AffinityMask; LONG BasePriority; ULONG UniqueProcessId; ULONG InheritedFromUniqueProcessId; } PBI, *PPBI; APR_DECLARE_LATE_DLL_FUNC(DLL_NTDLL, DWORD, WINAPI, NtQueryInformationProcess, 0, ( HANDLE hProcess, /* Obvious */ INT info, /* Use 0 for PBI documented above */ PVOID pPI, /* The PIB buffer */ ULONG LenPI, /* Use sizeof(PBI) */ ULONG *pSizePI), /* returns pPI buffer used (may pass NULL) */ (hProcess, info, pPI, LenPI, pSizePI)); #define QueryInformationProcess apr_winapi_NtQueryInformationProcess APR_DECLARE_LATE_DLL_FUNC(DLL_NTDLL, DWORD, WINAPI, NtQueryObject, 0, ( HANDLE hObject, /* Obvious */ INT info, /* Use 0 for PBI documented above */ PVOID pOI, /* The PIB buffer */ ULONG LenOI, /* Use sizeof(PBI) */ ULONG *pSizeOI), /* returns pPI buffer used (may pass NULL) */ (hObject, info, pOI, LenOI, pSizeOI)); #define QueryObject apr_winapi_NtQueryObject #endif /* !defined(_WIN32_WCE) */ #endif /* ! MISC_H */
001-log4cxx
trunk/src/apr/include/arch/win32/apr_arch_misc.h
C
asf20
11,824
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef INHERIT_H #define INHERIT_H #include "apr_inherit.h" #define APR_INHERIT (1 << 24) /* Must not conflict with other bits */ #define APR_IMPLEMENT_INHERIT_SET(name, flag, pool, cleanup) \ APR_DECLARE(apr_status_t) apr_##name##_inherit_set(apr_##name##_t *the##name) \ { \ IF_WIN_OS_IS_UNICODE \ { \ if (!SetHandleInformation(the##name->filehand, \ HANDLE_FLAG_INHERIT, \ HANDLE_FLAG_INHERIT)) \ return apr_get_os_error(); \ } \ ELSE_WIN_OS_IS_ANSI \ { \ HANDLE temp, hproc = GetCurrentProcess(); \ if (!DuplicateHandle(hproc, the##name->filehand, \ hproc, &temp, 0, TRUE, \ DUPLICATE_SAME_ACCESS)) \ return apr_get_os_error(); \ CloseHandle(the##name->filehand); \ the##name->filehand = temp; \ } \ return APR_SUCCESS; \ } #define APR_IMPLEMENT_INHERIT_UNSET(name, flag, pool, cleanup) \ APR_DECLARE(apr_status_t) apr_##name##_inherit_unset(apr_##name##_t *the##name)\ { \ IF_WIN_OS_IS_UNICODE \ { \ if (!SetHandleInformation(the##name->filehand, \ HANDLE_FLAG_INHERIT, 0)) \ return apr_get_os_error(); \ } \ ELSE_WIN_OS_IS_ANSI \ { \ HANDLE temp, hproc = GetCurrentProcess(); \ if (!DuplicateHandle(hproc, the##name->filehand, \ hproc, &temp, 0, FALSE, \ DUPLICATE_SAME_ACCESS)) \ return apr_get_os_error(); \ CloseHandle(the##name->filehand); \ the##name->filehand = temp; \ } \ return APR_SUCCESS; \ } #endif /* ! INHERIT_H */
001-log4cxx
trunk/src/apr/include/arch/win32/apr_arch_inherit.h
C
asf20
3,859
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef NETWORK_IO_H #define NETWORK_IO_H #include "apr_network_io.h" #include "apr_general.h" #include "apr_poll.h" typedef struct sock_userdata_t sock_userdata_t; struct sock_userdata_t { sock_userdata_t *next; const char *key; void *data; }; struct apr_socket_t { apr_pool_t *pool; SOCKET socketdes; int type; /* SOCK_STREAM, SOCK_DGRAM */ int protocol; apr_sockaddr_t *local_addr; apr_sockaddr_t *remote_addr; int timeout_ms; /* MUST MATCH if timeout > 0 */ apr_interval_time_t timeout; apr_int32_t disconnected; int local_port_unknown; int local_interface_unknown; int remote_addr_unknown; apr_int32_t options; apr_int32_t inherit; #if APR_HAS_SENDFILE /* As of 07.20.04, the overlapped structure is only used by * apr_socket_sendfile and that's where it will be allocated * and initialized. */ OVERLAPPED *overlapped; #endif sock_userdata_t *userdata; /* if there is a timeout set, then this pollset is used */ apr_pollset_t *pollset; }; #ifdef _WIN32_WCE #ifndef WSABUF typedef struct _WSABUF { u_long len; /* the length of the buffer */ char FAR * buf; /* the pointer to the buffer */ } WSABUF, FAR * LPWSABUF; #endif #else /* Not sure if this is the right place to define this */ #define HAVE_STRUCT_IPMREQ #endif apr_status_t status_from_res_error(int); const char *apr_inet_ntop(int af, const void *src, char *dst, apr_size_t size); int apr_inet_pton(int af, const char *src, void *dst); void apr_sockaddr_vars_set(apr_sockaddr_t *, int, apr_port_t); #define apr_is_option_set(skt, option) \ (((skt)->options & (option)) == (option)) #define apr_set_option(skt, option, on) \ do { \ if (on) \ (skt)->options |= (option); \ else \ (skt)->options &= ~(option); \ } while (0) #endif /* ! NETWORK_IO_H */
001-log4cxx
trunk/src/apr/include/arch/win32/apr_arch_networkio.h
C
asf20
2,964
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef APR_DBG_WIN32_HANDLES_H #define APR_DBG_WIN32_HANDLES_H #ifdef __cplusplus extern "C" { #endif /* USAGE: * * Add the following include to apr_private.h for internal debugging, * or copy this header into apr/include add the include below to apr.h * for really global debugging; * * #include "apr_dbg_win32_handles.h" * * apr_dbg_log is the crux of this function ... it uses Win32 API and * no apr calls itself to log all activity to a file named for the * executing application with a .pid suffix. Ergo several instances * may be executing and logged at once. * * HANDLE apr_dbg_log(char* fn, HANDLE ha, char* fl, int ln, int nh * [, HANDLE *hv, char *dsc...]) * * returns: the handle passed in ha, which is cast back to the real return type. * * formats one line into the debug log file if nh is zero; * ha (hex) seq(hex) tid(hex) fn fl ln * xxxxxxxx xxxxxxxx xxxxxxxx func() sourcefile:lineno * The macro apr_dbg_rv makes this simple to implement for many APIs * that simply take args that don't interest us, and return a handle. * * formats multiple lines (nh) into the debug log file for each hv/dsc pair * (nh must correspond to the number of pairs); * hv (hex) seq(hex) tid(hex) fn dsc fl ln * xxxxxxxx xxxxxxxx xxxxxxxx func(arg) sourcefile:lineno * In this later usage, hv is the still the return value but is not * treated as a handle. */ APR_DECLARE_NONSTD(HANDLE) apr_dbg_log(char* fn, HANDLE ha, char* fl, int ln, int nh,/* HANDLE *hv, char *dsc */...); #define apr_dbg_rv(fn, args) (apr_dbg_log(#fn,(fn) args,__FILE__,__LINE__,0)) #define CloseHandle(h) \ ((BOOL)apr_dbg_log("CloseHandle", \ (HANDLE)(CloseHandle)(h), \ __FILE__,__LINE__,1, \ &(h),"")) #define CreateEventA(sd,b1,b2,nm) apr_dbg_rv(CreateEventA,(sd,b1,b2,nm)) #define CreateEventW(sd,b1,b2,nm) apr_dbg_rv(CreateEventW,(sd,b1,b2,nm)) #define CreateFileA(nm,d1,d2,sd,d3,d4,h) apr_dbg_rv(CreateFileA,(nm,d1,d2,sd,d3,d4,h)) #define CreateFileW(nm,d1,d2,sd,d3,d4,h) apr_dbg_rv(CreateFileW,(nm,d1,d2,sd,d3,d4,h)) #define CreateFileMappingA(fh,sd,d1,d2,d3,nm) apr_dbg_rv(CreateFileMappingA,(fh,sd,d1,d2,d3,nm)) #define CreateFileMappingW(fh,sd,d1,d2,d3,nm) apr_dbg_rv(CreateFileMappingW,(fh,sd,d1,d2,d3,nm)) #define CreateMutexA(sd,b,nm) apr_dbg_rv(CreateMutexA,(sd,b,nm)) #define CreateMutexW(sd,b,nm) apr_dbg_rv(CreateMutexW,(sd,b,nm)) #define CreateIoCompletionPort(h1,h2,pd1,d2) apr_dbg_rv(CreateIoCompletionPort,(h1,h2,pd1,d2)) #define CreateNamedPipeA(nm,d1,d2,d3,d4,d5,d6,sd) apr_dbg_rv(CreateNamedPipeA,(nm,d1,d2,d3,d4,d5,d6,sd)) #define CreateNamedPipeW(nm,d1,d2,d3,d4,d5,d6,sd) apr_dbg_rv(CreateNamedPipeW,(nm,d1,d2,d3,d4,d5,d6,sd)) #define CreatePipe(ph1,ph2,sd,d) \ ((BOOL)apr_dbg_log("CreatePipe", \ (HANDLE)(CreatePipe)(ph1,ph2,sd,d), \ __FILE__,__LINE__,2, \ (ph1),"hRead", \ (ph2),"hWrite")) #define CreateProcessA(s1,s2,sd1,sd2,b,d1,s3,s4,pd2,hr) \ ((BOOL)apr_dbg_log("CreateProcessA", \ (HANDLE)(CreateProcessA)(s1,s2,sd1,sd2,b,d1,s3,s4,pd2,hr), \ __FILE__,__LINE__,2, \ &((hr)->hProcess),"hProcess", \ &((hr)->hThread),"hThread")) #define CreateProcessW(s1,s2,sd1,sd2,b,d1,s3,s4,pd2,hr) \ ((BOOL)apr_dbg_log("CreateProcessW", \ (HANDLE)(CreateProcessW)(s1,s2,sd1,sd2,b,d1,s3,s4,pd2,hr), \ __FILE__,__LINE__,2, \ &((hr)->hProcess),"hProcess", \ &((hr)->hThread),"hThread")) #define CreateSemaphoreA(sd,d1,d2,nm) apr_dbg_rv(CreateSemaphoreA,(sd,d1,d2,nm)) #define CreateSemaphoreW(sd,d1,d2,nm) apr_dbg_rv(CreateSemaphoreW,(sd,d1,d2,nm)) #define CreateThread(sd,d1,fn,pv,d2,pd3) apr_dbg_rv(CreateThread,(sd,d1,fn,pv,d2,pd3)) #define DeregisterEventSource(h) \ ((BOOL)apr_dbg_log("DeregisterEventSource", \ (HANDLE)(DeregisterEventSource)(h), \ __FILE__,__LINE__,1, \ &(h),"")) #define DuplicateHandle(h1,h2,h3,ph4,d1,b,d2) \ ((BOOL)apr_dbg_log("DuplicateHandle", \ (HANDLE)(DuplicateHandle)(h1,h2,h3,ph4,d1,b,d2), \ __FILE__,__LINE__,2, \ (ph4),((h3)==GetCurrentProcess()) \ ? "Target" : "EXTERN Target", \ &(h2),((h1)==GetCurrentProcess()) \ ? "Source" : "EXTERN Source")) #define GetCurrentProcess() \ (apr_dbg_log("GetCurrentProcess", \ (GetCurrentProcess)(),__FILE__,__LINE__,0)) #define GetCurrentThread() \ (apr_dbg_log("GetCurrentThread", \ (GetCurrentThread)(),__FILE__,__LINE__,0)) #define GetModuleHandleA(nm) apr_dbg_rv(GetModuleHandleA,(nm)) #define GetModuleHandleW(nm) apr_dbg_rv(GetModuleHandleW,(nm)) #define GetStdHandle(d) apr_dbg_rv(GetStdHandle,(d)) #define LoadLibraryA(nm) apr_dbg_rv(LoadLibraryA,(nm)) #define LoadLibraryW(nm) apr_dbg_rv(LoadLibraryW,(nm)) #define LoadLibraryExA(nm,h,d) apr_dbg_rv(LoadLibraryExA,(nm,h,d)) #define LoadLibraryExW(nm,h,d) apr_dbg_rv(LoadLibraryExW,(nm,h,d)) #define OpenEventA(d,b,nm) apr_dbg_rv(OpenEventA,(d,b,nm)) #define OpenEventW(d,b,nm) apr_dbg_rv(OpenEventW,(d,b,nm)) #define OpenFileMappingA(d,b,nm) apr_dbg_rv(OpenFileMappingA,(d,b,nm)) #define OpenFileMappingW(d,b,nm) apr_dbg_rv(OpenFileMappingW,(d,b,nm)) #define RegisterEventSourceA(s1,s2) apr_dbg_rv(RegisterEventSourceA,(s1,s2)) #define RegisterEventSourceW(s1,s2) apr_dbg_rv(RegisterEventSourceW,(s1,s2)) #define SetEvent(h) \ ((BOOL)apr_dbg_log("SetEvent", \ (HANDLE)(SetEvent)(h), \ __FILE__,__LINE__,1, \ &(h),"")) #define SetStdHandle(d,h) \ ((BOOL)apr_dbg_log("SetStdHandle", \ (HANDLE)(SetStdHandle)(d,h), \ __FILE__,__LINE__,1,&(h),"")) #define socket(i1,i2,i3) \ ((SOCKET)apr_dbg_log("socket", \ (HANDLE)(socket)(i1,i2,i3), \ __FILE__,__LINE__,0)) #define WaitForSingleObject(h,d) \ ((DWORD)apr_dbg_log("WaitForSingleObject", \ (HANDLE)(WaitForSingleObject)(h,d), \ __FILE__,__LINE__,1,&(h),"Signaled")) #define WaitForSingleObjectEx(h,d,b) \ ((DWORD)apr_dbg_log("WaitForSingleObjectEx", \ (HANDLE)(WaitForSingleObjectEx)(h,d,b), \ __FILE__,__LINE__,1,&(h),"Signaled")) #define WaitForMultipleObjects(d1,ah,b,d2) \ ((DWORD)apr_dbg_log("WaitForMultipleObjects", \ (HANDLE)(WaitForMultipleObjects)(d1,ah,b,d2), \ __FILE__,__LINE__,1,ah,"Signaled")) #define WaitForMultipleObjectsEx(d1,ah,b1,d2,b2) \ ((DWORD)apr_dbg_log("WaitForMultipleObjectsEx", \ (HANDLE)(WaitForMultipleObjectsEx)(d1,ah,b1,d2,b2), \ __FILE__,__LINE__,1,ah,"Signaled")) #define WSASocketA(i1,i2,i3,pi,g,dw) \ ((SOCKET)apr_dbg_log("WSASocketA", \ (HANDLE)(WSASocketA)(i1,i2,i3,pi,g,dw), \ __FILE__,__LINE__,0)) #define WSASocketW(i1,i2,i3,pi,g,dw) \ ((SOCKET)apr_dbg_log("WSASocketW", \ (HANDLE)(WSASocketW)(i1,i2,i3,pi,g,dw), \ __FILE__,__LINE__,0)) #define closesocket(sh) \ ((int)apr_dbg_log("closesocket", \ (HANDLE)(closesocket)(sh), \ __FILE__,__LINE__,1,&(sh),"")) #define _beginthread(fn,d,pv) \ ((unsigned long)apr_dbg_log("_beginthread", \ (HANDLE)(_beginthread)(fn,d,pv), \ __FILE__,__LINE__,0)) #define _beginthreadex(sd,d1,fn,pv,d2,pd3) \ ((unsigned long)apr_dbg_log("_beginthreadex", \ (HANDLE)(_beginthreadex)(sd,d1,fn,pv,d2,pd3), \ __FILE__,__LINE__,0)) #ifdef __cplusplus } #endif #endif /* !defined(APR_DBG_WIN32_HANDLES_H) */
001-log4cxx
trunk/src/apr/include/arch/win32/apr_dbg_win32_handles.h
C
asf20
9,113
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef UTF8_H #define UTF8_H #include "apr.h" #include "apr_lib.h" #include "apr_errno.h" /* If we ever support anything more exciting than char... this could move. */ typedef apr_uint16_t apr_wchar_t; /** * An APR internal function for fast utf-8 octet-encoded Unicode conversion * to the ucs-2 wide Unicode format. This function is used for filename and * other resource conversions for platforms providing native Unicode support. * * @tip Only the errors APR_EINVAL and APR_INCOMPLETE may occur, the former * when the character code is invalid (in or out of context) and the later * when more characters were expected, but insufficient characters remain. */ APR_DECLARE(apr_status_t) apr_conv_utf8_to_ucs2(const char *in, apr_size_t *inbytes, apr_wchar_t *out, apr_size_t *outwords); /** * An APR internal function for fast ucs-2 wide Unicode format conversion to * the utf-8 octet-encoded Unicode. This function is used for filename and * other resource conversions for platforms providing native Unicode support. * * @tip Only the errors APR_EINVAL and APR_INCOMPLETE may occur, the former * when the character code is invalid (in or out of context) and the later * when more words were expected, but insufficient words remain. */ APR_DECLARE(apr_status_t) apr_conv_ucs2_to_utf8(const apr_wchar_t *in, apr_size_t *inwords, char *out, apr_size_t *outbytes); #endif /* def UTF8_H */
001-log4cxx
trunk/src/apr/include/arch/win32/apr_arch_utf8.h
C
asf20
2,506
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "apr_private.h" #include "apr_thread_proc.h" #include "apr_file_io.h" #ifndef THREAD_PROC_H #define THREAD_PROC_H #define SHELL_PATH "cmd.exe" struct apr_thread_t { apr_pool_t *pool; HANDLE td; apr_int32_t cancel; apr_int32_t cancel_how; void *data; apr_thread_start_t func; apr_status_t exitval; }; struct apr_threadattr_t { apr_pool_t *pool; apr_int32_t detach; apr_size_t stacksize; }; struct apr_threadkey_t { apr_pool_t *pool; DWORD key; }; struct apr_procattr_t { apr_pool_t *pool; apr_file_t *parent_in; apr_file_t *child_in; apr_file_t *parent_out; apr_file_t *child_out; apr_file_t *parent_err; apr_file_t *child_err; char *currdir; apr_int32_t cmdtype; apr_int32_t detached; apr_child_errfn_t *errfn; apr_int32_t errchk; #ifndef _WIN32_WCE HANDLE user_token; LPSECURITY_ATTRIBUTES sa; LPVOID sd; #endif }; struct apr_thread_once_t { long value; }; #endif /* ! THREAD_PROC_H */
001-log4cxx
trunk/src/apr/include/arch/win32/apr_arch_threadproc.h
C
asf20
1,841
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef ATIME_H #define ATIME_H #include "apr_private.h" #include "apr_time.h" #if APR_HAVE_TIME_H #include <time.h> #endif struct atime_t { apr_pool_t *cntxt; apr_time_t currtime; SYSTEMTIME *explodedtime; }; /* Number of micro-seconds between the beginning of the Windows epoch * (Jan. 1, 1601) and the Unix epoch (Jan. 1, 1970) */ #define APR_DELTA_EPOCH_IN_USEC APR_TIME_C(11644473600000000); __inline void FileTimeToAprTime(apr_time_t *result, FILETIME *input) { /* Convert FILETIME one 64 bit number so we can work with it. */ *result = input->dwHighDateTime; *result = (*result) << 32; *result |= input->dwLowDateTime; *result /= 10; /* Convert from 100 nano-sec periods to micro-seconds. */ *result -= APR_DELTA_EPOCH_IN_USEC; /* Convert from Windows epoch to Unix epoch */ return; } __inline void AprTimeToFileTime(LPFILETIME pft, apr_time_t t) { LONGLONG ll; t += APR_DELTA_EPOCH_IN_USEC; ll = t * 10; pft->dwLowDateTime = (DWORD)ll; pft->dwHighDateTime = (DWORD) (ll >> 32); return; } #endif /* ! ATIME_H */
001-log4cxx
trunk/src/apr/include/arch/win32/apr_arch_atime.h
C
asf20
1,904
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef THREAD_RWLOCK_H #define THREAD_RWLOCK_H #include "apr_thread_rwlock.h" struct apr_thread_rwlock_t { apr_pool_t *pool; HANDLE write_mutex; HANDLE read_event; LONG readers; }; #endif /* THREAD_RWLOCK_H */
001-log4cxx
trunk/src/apr/include/arch/win32/apr_arch_thread_rwlock.h
C
asf20
1,049
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef THREAD_MUTEX_H #define THREAD_MUTEX_H #include "apr_pools.h" typedef enum thread_mutex_type { thread_mutex_critical_section, thread_mutex_unnested_event, thread_mutex_nested_mutex } thread_mutex_type; /* handle applies only to unnested_event on all platforms * and nested_mutex on Win9x only. Otherwise critical_section * is used for NT nexted mutexes providing optimal performance. */ struct apr_thread_mutex_t { apr_pool_t *pool; thread_mutex_type type; HANDLE handle; CRITICAL_SECTION section; }; #endif /* THREAD_MUTEX_H */
001-log4cxx
trunk/src/apr/include/arch/win32/apr_arch_thread_mutex.h
C
asf20
1,394
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef THREAD_COND_H #define THREAD_COND_H #include "apr_thread_cond.h" struct apr_thread_cond_t { apr_pool_t *pool; HANDLE event; int signal_all; int num_waiting; int signalled; }; #endif /* THREAD_COND_H */
001-log4cxx
trunk/src/apr/include/arch/win32/apr_arch_thread_cond.h
C
asf20
1,035
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* * Note: * This is the windows specific autoconf-like config file * which unix would create at build time. */ #ifdef WIN32 #ifndef APR_PRIVATE_H #define APR_PRIVATE_H /* Include the public APR symbols, include our idea of the 'right' * subset of the Windows.h header. This saves us repetition. */ #include "apr.h" /* * Add a _very_few_ declarations missing from the restricted set of headers * (If this list becomes extensive, re-enable the required headers above!) * winsock headers were excluded by WIN32_LEAN_AND_MEAN, so include them now */ #ifndef SW_HIDE #define SW_HIDE 0 #endif /* For the misc.h late-loaded dynamic symbols, we need some obscure types * Avoid dragging in wtypes.h unless it's absolutely necessary [generally * not with APR itself, until some GUI-related security is introduced.] */ #ifndef _WIN32_WCE #define HAVE_ACLAPI 1 #ifdef __wtypes_h__ #include <accctrl.h> #else #define __wtypes_h__ #include <accctrl.h> #undef __wtypes_h__ #endif #else #define HAVE_ACLAPI 0 #endif #if APR_HAVE_SYS_TYPES_H #include <sys/types.h> #endif #if APR_HAVE_STDDEF_H #include <stddef.h> #endif #include <stdio.h> #if APR_HAVE_TIME_H #include <time.h> #endif /* Use this section to define all of the HAVE_FOO_H * that are required to build properly. */ #define HAVE_LIMITS_H 1 #define HAVE_MALLOC_H 1 #define HAVE_SIGNAL_H 1 /* #define HAVE_STDDEF_H 1 why not? */ #define HAVE_STDLIB_H 1 #define HAVE_STRICMP 1 #define HAVE_STRNICMP 1 #define HAVE_STRDUP 1 #define HAVE_STRSTR 1 #define HAVE_MEMCHR 1 #define SIGHUP 1 /* 2 is used for SIGINT on windows */ #define SIGQUIT 3 /* 4 is used for SIGILL on windows */ #define SIGTRAP 5 #define SIGIOT 6 #define SIGBUS 7 /* 8 is used for SIGFPE on windows */ #define SIGKILL 9 #define SIGUSR1 10 /* 11 is used for SIGSEGV on windows */ #define SIGUSR2 12 #define SIGPIPE 13 #define SIGALRM 14 /* 15 is used for SIGTERM on windows */ #define SIGSTKFLT 16 #define SIGCHLD 17 #define SIGCONT 18 #define SIGSTOP 19 #define SIGTSTP 20 /* 21 is used for SIGBREAK on windows */ /* 22 is used for SIGABRT on windows */ #define SIGTTIN 23 #define SIGTTOU 24 #define SIGURG 25 #define SIGXCPU 26 #define SIGXFSZ 27 #define SIGVTALRM 28 #define SIGPROF 29 #define SIGWINCH 30 #define SIGIO 31 #define __attribute__(__x) /* APR COMPATABILITY FUNCTIONS * This section should be used to define functions and * macros which are need to make Windows features look * like POSIX features. */ typedef void (Sigfunc)(int); #define sleep(t) Sleep((t) * 1000) #define SIZEOF_SHORT 2 #define SIZEOF_INT 4 #define SIZEOF_LONGLONG 8 #define SIZEOF_CHAR 1 #define SIZEOF_SSIZE_T SIZEOF_INT unsigned __stdcall SignalHandling(void *); int thread_ready(void); #if !APR_HAVE_ERRNO_H APR_DECLARE_DATA int errno; #define ENOSPC 1 #endif #if APR_HAVE_IPV6 #define HAVE_GETADDRINFO 1 #define HAVE_GETNAMEINFO 1 #endif /* MSVC 7.0 introduced _strtoi64 */ #if _MSC_VER >= 1300 && _INTEGRAL_MAX_BITS >= 64 #define APR_INT64_STRFN _strtoi64 #endif #if APR_HAS_LARGE_FILES #ifdef APR_INT64_STRFN #define APR_OFF_T_STRFN APR_INT64_STRFN #else #define APR_OFF_T_STRFN apr_strtoi64 #endif #else #define APR_OFF_T_STRFN strtoi #endif /* used to check for DWORD overflow in 64bit compiles */ #define APR_DWORD_MAX 0xFFFFFFFFUL /* * Include common private declarations. */ #include "../apr_private_common.h" #endif /*APR_PRIVATE_H*/ #endif /*WIN32*/
001-log4cxx
trunk/src/apr/include/arch/win32/apr_private.h
C
asf20
4,394
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef FILE_IO_H #define FILE_IO_H #include "apr.h" #include "apr_private.h" #include "apr_pools.h" #include "apr_general.h" #include "apr_tables.h" #include "apr_thread_mutex.h" #include "apr_file_io.h" #include "apr_file_info.h" #include "apr_errno.h" #include "apr_arch_misc.h" #include "apr_poll.h" #ifdef HAVE_SYS_STAT_H #include <sys/stat.h> #endif #if APR_HAVE_SYS_TYPES_H #include <sys/types.h> #endif #ifdef HAVE_SYS_FCNTL_H #include <fcntl.h> #endif #ifdef HAVE_TIME_H #include <time.h> #endif #if APR_HAVE_DIRENT_H #include <dirent.h> #endif #ifdef HAVE_MALLOC_H #include <malloc.h> #endif #if APR_HAS_UNICODE_FS #include "arch/win32/apr_arch_utf8.h" #include <wchar.h> typedef apr_uint16_t apr_wchar_t; /* Helper functions for the WinNT ApiW() functions. APR treats all * resource identifiers (files, etc) by their UTF-8 name, to provide * access to all named identifiers. [UTF-8 completely maps Unicode * into char type strings.] * * The _path flavors below provide us fast mappings of the * Unicode filename //?/D:/path and //?/UNC/mach/share/path mappings, * which allow unlimited (well, 32000 wide character) length names. * These prefixes may appear in Unicode, but must not appear in the * Ascii API calls. So we tack them on in utf8_to_unicode_path, and * strip them right back off in unicode_to_utf8_path. */ apr_status_t utf8_to_unicode_path(apr_wchar_t* dststr, apr_size_t dstchars, const char* srcstr); apr_status_t unicode_to_utf8_path(char* dststr, apr_size_t dstchars, const apr_wchar_t* srcstr); #endif /* APR_HAS_UNICODE_FS */ /* Another Helper functions for the WinNT ApiW() functions. We need to * derive some 'resource' names (max length 255 characters, prefixed with * Global/ or Local/ on WinNT) from something that looks like a filename. * Since 'resource' names never contain slashes, convert these to '_'s * and return the appropriate char* or wchar* for ApiA or ApiW calls. */ void *res_name_from_filename(const char *file, int global, apr_pool_t *pool); #define APR_FILE_MAX MAX_PATH #define APR_FILE_BUFSIZE 4096 /* obscure ommissions from msvc's sys/stat.h */ #ifdef _MSC_VER #define S_IFIFO _S_IFIFO /* pipe */ #define S_IFBLK 0060000 /* Block Special */ #define S_IFLNK 0120000 /* Symbolic Link */ #define S_IFSOCK 0140000 /* Socket */ #define S_IFWHT 0160000 /* Whiteout */ #endif /* Internal Flags for apr_file_open */ #define APR_OPENINFO 0x00100000 /* Open without READ or WRITE access */ #define APR_OPENLINK 0x00200000 /* Open a link itself, if supported */ #define APR_READCONTROL 0x00400000 /* Read the file's owner/perms */ #define APR_WRITECONTROL 0x00800000 /* Modifythe file's owner/perms */ #define APR_WRITEATTRS 0x01000000 /* Modify the file's attributes */ /* Entries missing from the MSVC 5.0 Win32 SDK: */ #ifndef FILE_ATTRIBUTE_DEVICE #define FILE_ATTRIBUTE_DEVICE 0x00000040 #endif #ifndef FILE_ATTRIBUTE_REPARSE_POINT #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400 #endif #ifndef FILE_FLAG_OPEN_NO_RECALL #define FILE_FLAG_OPEN_NO_RECALL 0x00100000 #endif #ifndef FILE_FLAG_OPEN_REPARSE_POINT #define FILE_FLAG_OPEN_REPARSE_POINT 0x00200000 #endif #ifndef TRUSTEE_IS_WELL_KNOWN_GROUP #define TRUSTEE_IS_WELL_KNOWN_GROUP 5 #endif /* Information bits available from the WIN32 FindFirstFile function */ #define APR_FINFO_WIN32_DIR (APR_FINFO_NAME | APR_FINFO_TYPE \ | APR_FINFO_CTIME | APR_FINFO_ATIME \ | APR_FINFO_MTIME | APR_FINFO_SIZE) /* Sneak the Readonly bit through finfo->protection for internal use _only_ */ #define APR_FREADONLY 0x10000000 /* Private function for apr_stat/lstat/getfileinfo/dir_read */ int fillin_fileinfo(apr_finfo_t *finfo, WIN32_FILE_ATTRIBUTE_DATA *wininfo, int byhandle, apr_int32_t wanted); /* Private function that extends apr_stat/lstat/getfileinfo/dir_read */ apr_status_t more_finfo(apr_finfo_t *finfo, const void *ufile, apr_int32_t wanted, int whatfile); /* whatfile types for the ufile arg */ #define MORE_OF_HANDLE 0 #define MORE_OF_FSPEC 1 #define MORE_OF_WFSPEC 2 /* quick run-down of fields in windows' apr_file_t structure that may have * obvious uses. * fname -- the filename as passed to the open call. * dwFileAttricutes -- Attributes used to open the file. * append -- Windows doesn't support the append concept when opening files. * APR needs to keep track of this, and always make sure we append * correctly when writing to a file with this flag set TRUE. */ // for apr_poll.c; #define filedes filehand struct apr_file_t { apr_pool_t *pool; HANDLE filehand; BOOLEAN pipe; // Is this a pipe of a file? OVERLAPPED *pOverlapped; apr_interval_time_t timeout; apr_int32_t flags; /* File specific info */ apr_finfo_t *finfo; char *fname; DWORD dwFileAttributes; int eof_hit; BOOLEAN buffered; // Use buffered I/O? int ungetchar; // Last char provided by an unget op. (-1 = no char) int append; /* Stuff for buffered mode */ char *buffer; apr_size_t bufpos; // Read/Write position in buffer apr_size_t dataRead; // amount of valid data read into buffer int direction; // buffer being used for 0 = read, 1 = write apr_off_t filePtr; // position in file of handle apr_thread_mutex_t *mutex; // mutex semaphore, must be owned to access the above fields /* if there is a timeout set, then this pollset is used */ apr_pollset_t *pollset; /* Pipe specific info */ }; struct apr_dir_t { apr_pool_t *pool; HANDLE dirhand; apr_size_t rootlen; char *dirname; char *name; union { #if APR_HAS_UNICODE_FS struct { WIN32_FIND_DATAW *entry; } w; #endif #if APR_HAS_ANSI_FS struct { WIN32_FIND_DATAA *entry; } n; #endif }; int bof; }; /* There are many goofy characters the filesystem can't accept * or can confound the cmd.exe shell. Here's the list * [declared in filesys.c] */ extern const char apr_c_is_fnchar[256]; #define IS_FNCHAR(c) (apr_c_is_fnchar[(unsigned char)(c)] & 1) #define IS_SHCHAR(c) ((apr_c_is_fnchar[(unsigned char)(c)] & 2) == 2) /* If the user passes APR_FILEPATH_TRUENAME to either * apr_filepath_root or apr_filepath_merge, this fn determines * that the root really exists. It's expensive, wouldn't want * to do this too frequenly. */ apr_status_t filepath_root_test(char *path, apr_pool_t *p); /* The apr_filepath_merge wants to canonicalize the cwd to the * addpath if the user passes NULL as the old root path (this * isn't true of an empty string "", which won't be concatenated. * * But we need to figure out what the cwd of a given volume is, * when the user passes D:foo. This fn will determine D:'s cwd. * * If flags includes the bit APR_FILEPATH_NATIVE, the path returned * is in the os-native format. */ apr_status_t filepath_drive_get(char **rootpath, char drive, apr_int32_t flags, apr_pool_t *p); /* If the user passes d: vs. D: (or //mach/share vs. //MACH/SHARE), * we need to fold the case to canonical form. This function is * supposed to do so. */ apr_status_t filepath_root_case(char **rootpath, char *root, apr_pool_t *p); apr_status_t file_cleanup(void *); /** * Internal function to create a Win32/NT pipe that respects some async * timeout options. * @param in new read end of the created pipe * @param out new write end of the created pipe * @param blocking_mode one of * <pre> * APR_FULL_BLOCK * APR_READ_BLOCK * APR_WRITE_BLOCK * APR_FULL_NONBLOCK * </pre> * @remark It so happens that APR_FULL_BLOCK and APR_FULL_NONBLOCK * are common to apr_procattr_io_set() in, out and err modes. * Because APR_CHILD_BLOCK and APR_WRITE_BLOCK share the same value, * as do APR_PARENT_BLOCK and APR_READ_BLOCK, it's possible to use * that value directly for creating the stdout/stderr pipes. When * creating the stdin pipe, the values must be transposed. * @see apr_procattr_io_set */ apr_status_t apr_create_nt_pipe(apr_file_t **in, apr_file_t **out, apr_int32_t blocking_mode, apr_pool_t *p); /** @see apr_create_nt_pipe */ #define APR_READ_BLOCK 3 /** @see apr_create_nt_pipe */ #define APR_WRITE_BLOCK 4 #endif /* ! FILE_IO_H */
001-log4cxx
trunk/src/apr/include/arch/win32/apr_arch_file_io.h
C
asf20
9,429
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef DSO_H #define DSO_H #include "apr_private.h" #include "apr_general.h" #include "apr_pools.h" #include "apr_errno.h" #include "apr_dso.h" #include "apr.h" #include <kernel/image.h> #include <string.h> #if APR_HAS_DSO struct apr_dso_handle_t { image_id handle; /* Handle to the DSO loaded */ apr_pool_t *pool; const char *errormsg; /* if the load fails, we have an error * message here :) */ }; #endif #endif
001-log4cxx
trunk/src/apr/include/arch/beos/apr_arch_dso.h
C
asf20
1,305
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef PROC_MUTEX_H #define PROC_MUTEX_H #include "apr_pools.h" #include "apr_proc_mutex.h" #include "apr_file_io.h" #include "apr_general.h" #include "apr_lib.h" #include "apr_portable.h" struct apr_proc_mutex_t { apr_pool_t *pool; /* Our lock :) */ sem_id Lock; int32 LockCount; }; #endif /* PROC_MUTEX_H */
001-log4cxx
trunk/src/apr/include/arch/beos/apr_arch_proc_mutex.h
C
asf20
1,138
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "apr_thread_proc.h" #include "apr_arch_file_io.h" #include "apr_file_io.h" #include "apr_thread_proc.h" #include "apr_general.h" #include "apr_portable.h" #include <kernel/OS.h> #include <signal.h> #include <string.h> #include <sys/wait.h> #include <image.h> #ifndef THREAD_PROC_H #define THREAD_PROC_H #define SHELL_PATH "/bin/sh" #define PTHREAD_CANCEL_AYNCHRONOUS CANCEL_ASYNCH; #define PTHREAD_CANCEL_DEFERRED CANCEL_DEFER; #define PTHREAD_CANCEL_ENABLE CANCEL_ENABLE; #define PTHREAD_CANCEL_DISABLE CANCEL_DISABLE; #define BEOS_MAX_DATAKEYS 128 struct apr_thread_t { apr_pool_t *pool; thread_id td; void *data; apr_thread_start_t func; apr_status_t exitval; }; struct apr_threadattr_t { apr_pool_t *pool; int32 attr; int detached; int joinable; }; struct apr_threadkey_t { apr_pool_t *pool; int32 key; }; struct beos_private_data { const void ** data; int count; volatile thread_id td; }; struct beos_key { int assigned; int count; sem_id lock; int32 ben_lock; void (* destructor) (void *); }; struct apr_procattr_t { apr_pool_t *pool; apr_file_t *parent_in; apr_file_t *child_in; apr_file_t *parent_out; apr_file_t *child_out; apr_file_t *parent_err; apr_file_t *child_err; char *currdir; apr_int32_t cmdtype; apr_int32_t detached; }; struct apr_thread_once_t { sem_id sem; int hit; }; #endif /* ! THREAD_PROC_H */
001-log4cxx
trunk/src/apr/include/arch/beos/apr_arch_threadproc.h
C
asf20
2,303
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef THREAD_RWLOCK_H #define THREAD_RWLOCK_H #include <kernel/OS.h> #include "apr_pools.h" #include "apr_thread_rwlock.h" #include "apr_file_io.h" #include "apr_general.h" #include "apr_lib.h" #include "apr_portable.h" struct apr_thread_rwlock_t { apr_pool_t *pool; /* Our lock :) */ sem_id Lock; int32 LockCount; /* Read/Write lock stuff */ sem_id Read; int32 ReadCount; sem_id Write; int32 WriteCount; int32 Nested; thread_id writer; }; #endif /* THREAD_RWLOCK_H */
001-log4cxx
trunk/src/apr/include/arch/beos/apr_arch_thread_rwlock.h
C
asf20
1,326
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef THREAD_MUTEX_H #define THREAD_MUTEX_H #include <kernel/OS.h> #include "apr_pools.h" #include "apr_thread_mutex.h" #include "apr_file_io.h" #include "apr_general.h" #include "apr_lib.h" #include "apr_portable.h" struct apr_thread_mutex_t { apr_pool_t *pool; /* Our lock :) */ sem_id Lock; int32 LockCount; /* If we nest locks we need these... */ int nested; apr_os_thread_t owner; int owner_ref; }; #endif /* THREAD_MUTEX_H */
001-log4cxx
trunk/src/apr/include/arch/beos/apr_arch_thread_mutex.h
C
asf20
1,280
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef THREAD_COND_H #define THREAD_COND_H #include <kernel/OS.h> #include "apr_pools.h" #include "apr_thread_cond.h" #include "apr_file_io.h" #include "apr_general.h" #include "apr_lib.h" #include "apr_portable.h" #include "apr_ring.h" struct waiter_t { APR_RING_ENTRY(waiter_t) link; sem_id sem; }; struct apr_thread_cond_t { apr_pool_t *pool; sem_id lock; apr_thread_mutex_t *condlock; thread_id owner; /* active list */ APR_RING_HEAD(active_list, waiter_t) alist; /* free list */ APR_RING_HEAD(free_list, waiter_t) flist; }; #endif /* THREAD_COND_H */
001-log4cxx
trunk/src/apr/include/arch/beos/apr_arch_thread_cond.h
C
asf20
1,405
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef DSO_H #define DSO_H #include "apr_private.h" #include "apr_general.h" #include "apr_pools.h" #include "apr_dso.h" #include "apr.h" #if APR_HAS_DSO #ifdef HAVE_MACH_O_DYLD_H #include <mach-o/dyld.h> #endif #ifdef HAVE_DLFCN_H #include <dlfcn.h> #endif #ifdef HAVE_DL_H #include <dl.h> #endif #ifndef RTLD_NOW #define RTLD_NOW 1 #endif #ifndef RTLD_GLOBAL #define RTLD_GLOBAL 0 #endif #if (defined(__DragonFly__) ||\ defined(__FreeBSD__) ||\ defined(__OpenBSD__) ||\ defined(__NetBSD__) ) && !defined(__ELF__) #define DLSYM_NEEDS_UNDERSCORE #endif struct apr_dso_handle_t { apr_pool_t *pool; void *handle; const char *errormsg; }; #endif #endif
001-log4cxx
trunk/src/apr/include/arch/unix/apr_arch_dso.h
C
asf20
1,508
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef PROC_MUTEX_H #define PROC_MUTEX_H #include "apr.h" #include "apr_private.h" #include "apr_general.h" #include "apr_lib.h" #include "apr_proc_mutex.h" #include "apr_pools.h" #include "apr_portable.h" #include "apr_file_io.h" #include "apr_arch_file_io.h" /* System headers required by Locks library */ #if APR_HAVE_SYS_TYPES_H #include <sys/types.h> #endif #if APR_HAVE_STDIO_H #include <stdio.h> #endif #if APR_HAVE_FCNTL_H #include <fcntl.h> #endif #ifdef HAVE_SYS_IPC_H #include <sys/ipc.h> #endif #ifdef HAVE_SYS_SEM_H #include <sys/sem.h> #endif #ifdef HAVE_SYS_FILE_H #include <sys/file.h> #endif #if APR_HAVE_STDLIB_H #include <stdlib.h> #endif #if APR_HAVE_UNISTD_H #include <unistd.h> #endif #if APR_HAVE_STRING_H #include <string.h> #endif #ifdef HAVE_SYS_MMAN_H #include <sys/mman.h> #endif #if APR_HAVE_PTHREAD_H #include <pthread.h> #endif #if APR_HAVE_SEMAPHORE_H #include <semaphore.h> #endif /* End System Headers */ struct apr_proc_mutex_unix_lock_methods_t { unsigned int flags; apr_status_t (*create)(apr_proc_mutex_t *, const char *); apr_status_t (*acquire)(apr_proc_mutex_t *); apr_status_t (*tryacquire)(apr_proc_mutex_t *); apr_status_t (*release)(apr_proc_mutex_t *); apr_status_t (*cleanup)(void *); apr_status_t (*child_init)(apr_proc_mutex_t **, apr_pool_t *, const char *); const char *name; }; typedef struct apr_proc_mutex_unix_lock_methods_t apr_proc_mutex_unix_lock_methods_t; /* bit values for flags field in apr_unix_lock_methods_t */ #define APR_PROCESS_LOCK_MECH_IS_GLOBAL 1 #if !APR_HAVE_UNION_SEMUN && defined(APR_HAS_SYSVSEM_SERIALIZE) union semun { int val; struct semid_ds *buf; unsigned short *array; }; #endif struct apr_proc_mutex_t { apr_pool_t *pool; const apr_proc_mutex_unix_lock_methods_t *meth; const apr_proc_mutex_unix_lock_methods_t *inter_meth; int curr_locked; char *fname; #if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE apr_file_t *interproc; #endif #if APR_HAS_POSIXSEM_SERIALIZE sem_t *psem_interproc; #endif #if APR_HAS_PROC_PTHREAD_SERIALIZE pthread_mutex_t *pthread_interproc; #endif }; void apr_proc_mutex_unix_setup_lock(void); #endif /* PROC_MUTEX_H */
001-log4cxx
trunk/src/apr/include/arch/unix/apr_arch_proc_mutex.h
C
asf20
3,058
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef MISC_H #define MISC_H #include "apr.h" #include "apr_portable.h" #include "apr_private.h" #include "apr_general.h" #include "apr_pools.h" #include "apr_getopt.h" #include "apr_thread_proc.h" #include "apr_file_io.h" #include "apr_errno.h" #include "apr_getopt.h" #if APR_HAVE_STDIO_H #include <stdio.h> #endif #if APR_HAVE_SIGNAL_H #include <signal.h> #endif #if APR_HAVE_PTHREAD_H #include <pthread.h> #endif #if APR_HAVE_STDLIB_H #include <stdlib.h> #endif #if APR_HAVE_STRING_H #include <string.h> #endif #ifdef BEOS #include <kernel/OS.h> #endif struct apr_other_child_rec_t { apr_pool_t *p; struct apr_other_child_rec_t *next; apr_proc_t *proc; void (*maintenance) (int, void *, int); void *data; apr_os_file_t write_fd; }; #if defined(WIN32) || defined(NETWARE) #define WSAHighByte 2 #define WSALowByte 0 #endif #endif /* ! MISC_H */
001-log4cxx
trunk/src/apr/include/arch/unix/apr_arch_misc.h
C
asf20
1,681
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef INHERIT_H #define INHERIT_H #include "apr_inherit.h" #define APR_INHERIT (1 << 24) /* Must not conflict with other bits */ #define APR_IMPLEMENT_INHERIT_SET(name, flag, pool, cleanup) \ apr_status_t apr_##name##_inherit_set(apr_##name##_t *the##name) \ { \ if (the##name->flag & APR_FILE_NOCLEANUP) \ return APR_EINVAL; \ if (!(the##name->flag & APR_INHERIT)) { \ the##name->flag |= APR_INHERIT; \ apr_pool_child_cleanup_set(the##name->pool, \ (void *)the##name, \ cleanup, apr_pool_cleanup_null); \ } \ return APR_SUCCESS; \ } #define APR_IMPLEMENT_INHERIT_UNSET(name, flag, pool, cleanup) \ apr_status_t apr_##name##_inherit_unset(apr_##name##_t *the##name) \ { \ if (the##name->flag & APR_FILE_NOCLEANUP) \ return APR_EINVAL; \ if (the##name->flag & APR_INHERIT) { \ the##name->flag &= ~APR_INHERIT; \ apr_pool_child_cleanup_set(the##name->pool, \ (void *)the##name, \ cleanup, cleanup); \ } \ return APR_SUCCESS; \ } #endif /* ! INHERIT_H */
001-log4cxx
trunk/src/apr/include/arch/unix/apr_arch_inherit.h
C
asf20
2,648
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef NETWORK_IO_H #define NETWORK_IO_H #include "apr.h" #include "apr_private.h" #include "apr_network_io.h" #include "apr_errno.h" #include "apr_general.h" #include "apr_lib.h" #ifndef WAITIO_USES_POLL #include "apr_poll.h" #endif /* System headers the network I/O library needs */ #if APR_HAVE_SYS_TYPES_H #include <sys/types.h> #endif #if APR_HAVE_SYS_UIO_H #include <sys/uio.h> #endif #ifdef HAVE_SYS_SELECT_H #include <sys/select.h> #endif #if APR_HAVE_ERRNO_H #include <errno.h> #endif #if APR_HAVE_SYS_TIME_H #include <sys/time.h> #endif #if APR_HAVE_UNISTD_H #include <unistd.h> #endif #if APR_HAVE_STRING_H #include <string.h> #endif #if APR_HAVE_NETINET_TCP_H #include <netinet/tcp.h> #endif #if APR_HAVE_NETINET_SCTP_UIO_H #include <netinet/sctp_uio.h> #endif #if APR_HAVE_NETINET_SCTP_H #include <netinet/sctp.h> #endif #if APR_HAVE_NETINET_IN_H #include <netinet/in.h> #endif #if APR_HAVE_ARPA_INET_H #include <arpa/inet.h> #endif #if APR_HAVE_SYS_SOCKET_H #include <sys/socket.h> #endif #if APR_HAVE_SYS_SOCKIO_H #include <sys/sockio.h> #endif #if APR_HAVE_NETDB_H #include <netdb.h> #endif #if APR_HAVE_FCNTL_H #include <fcntl.h> #endif #if APR_HAVE_SYS_SENDFILE_H #include <sys/sendfile.h> #endif #if APR_HAVE_SYS_IOCTL_H #include <sys/ioctl.h> #endif /* End System Headers */ #ifndef HAVE_POLLIN #define POLLIN 1 #define POLLPRI 2 #define POLLOUT 4 #define POLLERR 8 #define POLLHUP 16 #define POLLNVAL 32 #endif typedef struct sock_userdata_t sock_userdata_t; struct sock_userdata_t { sock_userdata_t *next; const char *key; void *data; }; struct apr_socket_t { apr_pool_t *pool; int socketdes; int type; int protocol; apr_sockaddr_t *local_addr; apr_sockaddr_t *remote_addr; apr_interval_time_t timeout; #ifndef HAVE_POLL int connected; #endif int local_port_unknown; int local_interface_unknown; int remote_addr_unknown; apr_int32_t options; apr_int32_t inherit; sock_userdata_t *userdata; #ifndef WAITIO_USES_POLL /* if there is a timeout set, then this pollset is used */ apr_pollset_t *pollset; #endif }; const char *apr_inet_ntop(int af, const void *src, char *dst, apr_size_t size); int apr_inet_pton(int af, const char *src, void *dst); void apr_sockaddr_vars_set(apr_sockaddr_t *, int, apr_port_t); #define apr_is_option_set(skt, option) \ (((skt)->options & (option)) == (option)) #define apr_set_option(skt, option, on) \ do { \ if (on) \ (skt)->options |= (option); \ else \ (skt)->options &= ~(option); \ } while (0) #endif /* ! NETWORK_IO_H */
001-log4cxx
trunk/src/apr/include/arch/unix/apr_arch_networkio.h
C
asf20
3,526
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef GLOBAL_MUTEX_H #define GLOBAL_MUTEX_H #include "apr.h" #include "apr_private.h" #include "apr_general.h" #include "apr_lib.h" #include "apr_global_mutex.h" #include "apr_arch_proc_mutex.h" #include "apr_arch_thread_mutex.h" struct apr_global_mutex_t { apr_pool_t *pool; apr_proc_mutex_t *proc_mutex; #if APR_HAS_THREADS apr_thread_mutex_t *thread_mutex; #endif /* APR_HAS_THREADS */ }; #endif /* GLOBAL_MUTEX_H */
001-log4cxx
trunk/src/apr/include/arch/unix/apr_arch_global_mutex.h
C
asf20
1,239
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef TIME_INTERNAL_H #define TIME_INTERNAL_H #include "apr.h" void apr_unix_setup_time(void); #endif /* TIME_INTERNAL_H */
001-log4cxx
trunk/src/apr/include/arch/unix/apr_arch_internal_time.h
C
asf20
930
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "apr.h" #include "apr_private.h" #include "apr_thread_proc.h" #include "apr_file_io.h" #include "apr_arch_file_io.h" /* System headers required for thread/process library */ #if APR_HAVE_PTHREAD_H #include <pthread.h> #endif #ifdef HAVE_SYS_RESOURCE_H #include <sys/resource.h> #endif #if APR_HAVE_SIGNAL_H #include <signal.h> #endif #if APR_HAVE_STRING_H #include <string.h> #endif #if APR_HAVE_SYS_WAIT_H #include <sys/wait.h> #endif #if APR_HAVE_STRING_H #include <string.h> #endif /* End System Headers */ #ifndef THREAD_PROC_H #define THREAD_PROC_H #define SHELL_PATH "/bin/sh" #if APR_HAS_THREADS struct apr_thread_t { apr_pool_t *pool; pthread_t *td; void *data; apr_thread_start_t func; apr_status_t exitval; }; struct apr_threadattr_t { apr_pool_t *pool; pthread_attr_t attr; }; struct apr_threadkey_t { apr_pool_t *pool; pthread_key_t key; }; struct apr_thread_once_t { pthread_once_t once; }; #endif struct apr_procattr_t { apr_pool_t *pool; apr_file_t *parent_in; apr_file_t *child_in; apr_file_t *parent_out; apr_file_t *child_out; apr_file_t *parent_err; apr_file_t *child_err; char *currdir; apr_int32_t cmdtype; apr_int32_t detached; #ifdef RLIMIT_CPU struct rlimit *limit_cpu; #endif #if defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined(RLIMIT_AS) struct rlimit *limit_mem; #endif #ifdef RLIMIT_NPROC struct rlimit *limit_nproc; #endif #ifdef RLIMIT_NOFILE struct rlimit *limit_nofile; #endif apr_child_errfn_t *errfn; apr_int32_t errchk; apr_uid_t uid; apr_gid_t gid; }; #endif /* ! THREAD_PROC_H */
001-log4cxx
trunk/src/apr/include/arch/unix/apr_arch_threadproc.h
C
asf20
2,466
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef THREAD_RWLOCK_H #define THREAD_RWLOCK_H #include "apr.h" #include "apr_private.h" #include "apr_general.h" #include "apr_thread_rwlock.h" #include "apr_pools.h" #if APR_HAVE_PTHREAD_H /* this gives us pthread_rwlock_t */ #include <pthread.h> #endif #if APR_HAS_THREADS #ifdef HAVE_PTHREAD_RWLOCKS struct apr_thread_rwlock_t { apr_pool_t *pool; pthread_rwlock_t rwlock; }; #else struct apr_thread_rwlock_t { apr_pool_t *pool; }; #endif #endif #endif /* THREAD_RWLOCK_H */
001-log4cxx
trunk/src/apr/include/arch/unix/apr_arch_thread_rwlock.h
C
asf20
1,301
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef THREAD_MUTEX_H #define THREAD_MUTEX_H #include "apr.h" #include "apr_private.h" #include "apr_general.h" #include "apr_thread_mutex.h" #include "apr_portable.h" #include "apr_atomic.h" #if APR_HAVE_PTHREAD_H #include <pthread.h> #endif #if APR_HAS_THREADS struct apr_thread_mutex_t { apr_pool_t *pool; pthread_mutex_t mutex; }; #endif #endif /* THREAD_MUTEX_H */
001-log4cxx
trunk/src/apr/include/arch/unix/apr_arch_thread_mutex.h
C
asf20
1,185
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef SHM_H #define SHM_H #include "apr.h" #include "apr_private.h" #include "apr_general.h" #include "apr_lib.h" #include "apr_shm.h" #include "apr_pools.h" #include "apr_file_io.h" #include "apr_network_io.h" #include "apr_portable.h" #ifdef HAVE_SYS_MMAN_H #include <sys/mman.h> #endif #ifdef HAVE_SYS_IPC_H #include <sys/ipc.h> #endif #ifdef HAVE_SYS_MUTEX_H #include <sys/mutex.h> #endif #ifdef HAVE_SYS_SHM_H #include <sys/shm.h> #endif #if !defined(SHM_R) #define SHM_R 0400 #endif #if !defined(SHM_W) #define SHM_W 0200 #endif #ifdef HAVE_SYS_FILE_H #include <sys/file.h> #endif /* Not all systems seem to have MAP_FAILED defined, but it should always * just be (void *)-1. */ #ifndef MAP_FAILED #define MAP_FAILED ((void *)-1) #endif struct apr_shm_t { apr_pool_t *pool; void *base; /* base real address */ void *usable; /* base usable address */ apr_size_t reqsize; /* requested segment size */ apr_size_t realsize; /* actual segment size */ const char *filename; /* NULL if anonymous */ #if APR_USE_SHMEM_SHMGET || APR_USE_SHMEM_SHMGET_ANON int shmid; /* shmem ID returned from shmget() */ #endif }; #endif /* SHM_H */
001-log4cxx
trunk/src/apr/include/arch/unix/apr_arch_shm.h
C
asf20
1,997
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef THREAD_COND_H #define THREAD_COND_H #include "apr.h" #include "apr_private.h" #include "apr_general.h" #include "apr_lib.h" #include "apr_thread_mutex.h" #include "apr_thread_cond.h" #include "apr_pools.h" #if APR_HAVE_PTHREAD_H #include <pthread.h> #endif /* XXX: Should we have a better autoconf search, something like * APR_HAS_PTHREAD_COND? -aaron */ #if APR_HAS_THREADS struct apr_thread_cond_t { apr_pool_t *pool; pthread_cond_t cond; }; #endif #endif /* THREAD_COND_H */
001-log4cxx
trunk/src/apr/include/arch/unix/apr_arch_thread_cond.h
C
asf20
1,301
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef APR_ARCH_POLL_PRIVATE_H #define APR_ARCH_POLL_PRIVATE_H #include "apr.h" #include "apr_poll.h" #include "apr_time.h" #include "apr_portable.h" #include "apr_arch_networkio.h" #include "apr_arch_file_io.h" #if HAVE_POLL_H #include <poll.h> #endif #if HAVE_SYS_POLL_H #include <sys/poll.h> #endif #ifdef HAVE_PORT_CREATE #include <port.h> #include <sys/port_impl.h> #endif #ifdef HAVE_KQUEUE #include <sys/types.h> #include <sys/event.h> #include <sys/time.h> #endif #ifdef HAVE_EPOLL #include <sys/epoll.h> #endif #ifdef NETWARE #define HAS_SOCKETS(dt) (dt == APR_POLL_SOCKET) ? 1 : 0 #define HAS_PIPES(dt) (dt == APR_POLL_FILE) ? 1 : 0 #endif /* Choose the best method platform specific to use in apr_pollset */ #ifdef HAVE_KQUEUE #define POLLSET_USES_KQUEUE #elif defined(HAVE_PORT_CREATE) #define POLLSET_USES_PORT #elif defined(HAVE_EPOLL) #define POLLSET_USES_EPOLL #elif defined(HAVE_POLL) #define POLLSET_USES_POLL #else #define POLLSET_USES_SELECT #endif #ifdef HAVE_POLL #define POLL_USES_POLL #else #define POLL_USES_SELECT #endif #if defined(POLLSET_USES_KQUEUE) || defined(POLLSET_USES_EPOLL) || defined(POLLSET_USES_PORT) #include "apr_ring.h" #if APR_HAS_THREADS #include "apr_thread_mutex.h" #define pollset_lock_rings() \ if (pollset->flags & APR_POLLSET_THREADSAFE) \ apr_thread_mutex_lock(pollset->ring_lock); #define pollset_unlock_rings() \ if (pollset->flags & APR_POLLSET_THREADSAFE) \ apr_thread_mutex_unlock(pollset->ring_lock); #else #define pollset_lock_rings() #define pollset_unlock_rings() #endif typedef struct pfd_elem_t pfd_elem_t; struct pfd_elem_t { APR_RING_ENTRY(pfd_elem_t) link; apr_pollfd_t pfd; }; #endif #endif /* APR_ARCH_POLL_PRIVATE_H */
001-log4cxx
trunk/src/apr/include/arch/unix/apr_arch_poll_private.h
C
asf20
2,537
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef FILE_IO_H #define FILE_IO_H #include "apr.h" #include "apr_private.h" #include "apr_general.h" #include "apr_tables.h" #include "apr_file_io.h" #include "apr_file_info.h" #include "apr_errno.h" #include "apr_lib.h" #include "apr_thread_mutex.h" #ifndef WAITIO_USES_POLL #include "apr_poll.h" #endif /* System headers the file I/O library needs */ #if APR_HAVE_FCNTL_H #include <fcntl.h> #endif #if APR_HAVE_SYS_TYPES_H #include <sys/types.h> #endif #if APR_HAVE_ERRNO_H #include <errno.h> #endif #if APR_HAVE_STRING_H #include <string.h> #endif #if APR_HAVE_STRINGS_H #include <strings.h> #endif #if APR_HAVE_DIRENT_H #include <dirent.h> #endif #ifdef HAVE_SYS_STAT_H #include <sys/stat.h> #endif #if APR_HAVE_UNISTD_H #include <unistd.h> #endif #if APR_HAVE_STDIO_H #include <stdio.h> #endif #if APR_HAVE_STDLIB_H #include <stdlib.h> #endif #if APR_HAVE_SYS_UIO_H #include <sys/uio.h> #endif #if APR_HAVE_SYS_TIME_H #include <sys/time.h> #endif #ifdef BEOS #include <kernel/OS.h> #endif #if BEOS_BONE # ifndef BONE7 /* prior to BONE/7 fd_set & select were defined in sys/socket.h */ # include <sys/socket.h> # else /* Be moved the fd_set stuff and also the FIONBIO definition... */ # include <sys/ioctl.h> # endif #endif /* End System headers */ #define APR_FILE_BUFSIZE 4096 struct apr_file_t { apr_pool_t *pool; int filedes; char *fname; apr_int32_t flags; int eof_hit; int is_pipe; apr_interval_time_t timeout; int buffered; enum {BLK_UNKNOWN, BLK_OFF, BLK_ON } blocking; int ungetchar; /* Last char provided by an unget op. (-1 = no char)*/ #ifndef WAITIO_USES_POLL /* if there is a timeout set, then this pollset is used */ apr_pollset_t *pollset; #endif /* Stuff for buffered mode */ char *buffer; int bufpos; /* Read/Write position in buffer */ unsigned long dataRead; /* amount of valid data read into buffer */ int direction; /* buffer being used for 0 = read, 1 = write */ apr_off_t filePtr; /* position in file of handle */ #if APR_HAS_THREADS struct apr_thread_mutex_t *thlock; #endif }; #if APR_HAS_LARGE_FILES && defined(_LARGEFILE64_SOURCE) #define stat(f,b) stat64(f,b) #define lstat(f,b) lstat64(f,b) #define fstat(f,b) fstat64(f,b) #define lseek(f,o,w) lseek64(f,o,w) #define ftruncate(f,l) ftruncate64(f,l) typedef struct stat64 struct_stat; #else typedef struct stat struct_stat; #endif struct apr_dir_t { apr_pool_t *pool; char *dirname; DIR *dirstruct; struct dirent *entry; }; apr_status_t apr_unix_file_cleanup(void *); mode_t apr_unix_perms2mode(apr_fileperms_t perms); apr_fileperms_t apr_unix_mode2perms(mode_t mode); #endif /* ! FILE_IO_H */
001-log4cxx
trunk/src/apr/include/arch/unix/apr_arch_file_io.h
C
asf20
3,527