Skip to content

Commit 37884c4

Browse files
tenderlovematzbot
authored andcommitted
[ruby/fcntl] Add macOS specific flags around file preallocation
I wanted to use file preallocation with fcntl, but the flags weren't available. This commit just adds the missing flags. ruby/fcntl@7d4ab83a84
1 parent 8f040a5 commit 37884c4

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

ext/fcntl/fcntl.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,50 @@ Init_fcntl(void)
251251
*/
252252
rb_define_const(mFcntl, "F_DUP2FD_CLOEXEC", INT2NUM(F_DUP2FD_CLOEXEC));
253253
#endif
254+
255+
#ifdef F_PREALLOCATE
256+
/*
257+
* macOS specific flag used for preallocating file space.
258+
*/
259+
rb_define_const(mFcntl, "F_PREALLOCATE", INT2NUM(F_PREALLOCATE));
260+
#endif
261+
262+
#ifdef F_ALLOCATECONTIG
263+
/*
264+
* macOS specific flag used with F_PREALLOCATE for allocating contiguous
265+
* space.
266+
*/
267+
rb_define_const(mFcntl, "F_ALLOCATECONTIG", INT2NUM(F_ALLOCATECONTIG));
268+
#endif
269+
270+
#ifdef F_ALLOCATEALL
271+
/*
272+
* macOS specific flag used with F_PREALLOCATE for allocating all contiguous
273+
* space or no space.
274+
*/
275+
rb_define_const(mFcntl, "F_ALLOCATEALL", INT2NUM(F_ALLOCATEALL));
276+
#endif
277+
278+
#ifdef F_ALLOCATEPERSIST
279+
/*
280+
* macOS specific flag used with F_PREALLOCATE. Allocate space that is not
281+
* freed when close is called.
282+
*/
283+
rb_define_const(mFcntl, "F_ALLOCATEPERSIST", INT2NUM(F_ALLOCATEPERSIST));
284+
#endif
285+
286+
#ifdef F_PEOFPOSMODE
287+
/*
288+
* macOS specific flag used with F_PREALLOCATE. Allocate from the physical
289+
* end of file
290+
*/
291+
rb_define_const(mFcntl, "F_PEOFPOSMODE", INT2NUM(F_PEOFPOSMODE));
292+
#endif
293+
294+
#ifdef F_VOLPOSMODE
295+
/*
296+
* macOS specific flag used with F_PREALLOCATE. Allocate from the volume offset.
297+
*/
298+
rb_define_const(mFcntl, "F_VOLPOSMODE", INT2NUM(F_VOLPOSMODE));
299+
#endif
254300
}

0 commit comments

Comments
 (0)