2
0

tryread.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "testflock.h"
  17. #include "fspr_pools.h"
  18. #include "fspr_file_io.h"
  19. #include "fspr_general.h"
  20. #include "fspr.h"
  21. #if APR_HAVE_STDLIB_H
  22. #include <stdlib.h>
  23. #endif
  24. int main(int argc, const char * const *argv)
  25. {
  26. fspr_file_t *file;
  27. fspr_status_t status;
  28. fspr_pool_t *p;
  29. fspr_initialize();
  30. fspr_pool_create(&p, NULL);
  31. if (fspr_file_open(&file, TESTFILE, APR_WRITE, APR_OS_DEFAULT, p)
  32. != APR_SUCCESS) {
  33. exit(UNEXPECTED_ERROR);
  34. }
  35. status = fspr_file_lock(file, APR_FLOCK_EXCLUSIVE | APR_FLOCK_NONBLOCK);
  36. if (status == APR_SUCCESS) {
  37. exit(SUCCESSFUL_READ);
  38. }
  39. if (APR_STATUS_IS_EAGAIN(status)) {
  40. exit(FAILED_READ);
  41. }
  42. exit(UNEXPECTED_ERROR);
  43. }