file.cpp 479 B

12345678910111213141516171819202122
  1. /*
  2. * Copyright (c) 2021, Peter Elliott <pelliott@serenityos.org>
  3. * Copyright (c) 2022, Idan Horowitz <idan.horowitz@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <AK/Assertions.h>
  8. #include <fcntl.h>
  9. #include <stdio.h>
  10. #include <sys/file.h>
  11. extern "C" {
  12. int flock(int fd, int operation)
  13. {
  14. struct flock lock {
  15. short(operation & 0b11), SEEK_SET, 0, 0, 0
  16. };
  17. return fcntl(fd, (operation & LOCK_NB) ? F_SETLK : F_SETLKW, &lock);
  18. }
  19. }