Lines Matching refs:fd
192 flock_fd(int fd, int cmd, pthread_mutex_t *mutex)
200 while ((ret = fcntl(fd, F_SETLKW, &fl)) == -1) {
215 int fd;
217 fd = open_nointr(filename, mode|O_NONBLOCK);
218 if (fd < 0)
219 return (fd);
221 if (flock_fd(fd, cmd, mutex)) {
222 if (fd > 0)
223 (void) close(fd);
227 return (fd);
231 kms_slurp_fd(int fd, char *buf, size_t buflen)
235 n = readn_nointr(fd, &buf[total], buflen - total);
247 int fd, total = 0;
249 fd = open_and_lock_file(file, F_RDLCK, O_RDONLY, &flock_mutex);
250 if (fd == -1)
253 total = kms_slurp_fd(fd, buf, buflen);
255 if (flock_fd(fd, F_UNLCK, &flock_mutex))
258 (void) close(fd);
1057 int fd;
1068 fd = open_and_lock_file(labelfile, F_WRLCK, O_RDWR | O_CREAT,
1070 if (fd == -1)
1073 if (fstat(fd, &statp) == -1) {
1074 (void) flock_fd(fd, F_UNLCK, &flock_mutex);
1075 (void) close(fd);
1083 (void) flock_fd(fd, F_UNLCK, &flock_mutex);
1084 (void) close(fd);
1087 bytes = kms_slurp_fd(fd, buf, statp.st_size);
1094 if (ftruncate(fd, 0) == -1) {
1095 (void) flock_fd(fd, F_UNLCK, &flock_mutex);
1096 (void) close(fd);
1099 (void) lseek(fd, 0, SEEK_SET);
1101 fp = fdopen(fd, "w+");
1103 (void) flock_fd(fd, F_UNLCK, &flock_mutex);
1104 (void) close(fd);
1129 if (fstat(fd, &statp) == 0)
1132 (void) flock_fd(fd, F_UNLCK, &flock_mutex);