_fcntl.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include <lib.h>
  2. #define fcntl _fcntl
  3. #include <fcntl.h>
  4. #if _ANSI
  5. #endif
  6. #if _ANSI
  7. #include <stdarg.h>
  8. PUBLIC int fcntl(int fd, int cmd, ...)
  9. {
  10. #else
  11. #include <varargs.h>
  12. PUBLIC int fcntl(va_alist)
  13. va_dcl
  14. {
  15. int fd;
  16. int cmd;
  17. #endif
  18. va_list ap;
  19. int int3; /* third integer parameter for callm1 */
  20. char *ptr1; /* first pointer parameter for callm1 */
  21. #if _ANSI
  22. va_start(ap, cmd);
  23. #else
  24. va_start(ap);
  25. fd = va_arg(ap, int);
  26. cmd = va_arg(ap, int);
  27. #endif
  28. /* Set up for the sensible case where there is no variable parameter. This
  29. * covers F_GETFD, F_GETFL and invalid commands.
  30. */
  31. int3 = 0;
  32. ptr1 = NIL_PTR;
  33. /* Adjust for the stupid cases. */
  34. switch(cmd) {
  35. case F_DUPFD:
  36. case F_SETFD:
  37. case F_SETFL:
  38. int3 = va_arg(ap, int);
  39. break;
  40. case F_GETLK:
  41. case F_SETLK:
  42. case F_SETLKW:
  43. ptr1 = (char *) va_arg(ap, struct flock *);
  44. break;
  45. }
  46. /* Clean up and make the system call. */
  47. va_end(ap);
  48. return(_callm1(FS, FCNTL, fd, cmd, int3, ptr1, NIL_PTR, NIL_PTR));
  49. }