Skip to content

Commit 9cd7752

Browse files
committed
No cfile support for 32bit systems
In principle we could support it with a few more extra macros to figure out if we should use `enif_get_int64()` vs `enif_get_int()` for `size_t` values, but since we don't have a way to test it (no CI machine for armhf), we'll just opt to not support it for now. This doesn't mean we'd crash the build: we still support 32bit systems just with a default file module, like we do on Windows.
1 parent 0b85b41 commit 9cd7752

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/couch/priv/couch_cfile/couch_cfile.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@
1111
// the License.
1212

1313

14-
#ifndef _WIN32
14+
// Not supported on Windows or 32 bit architectures. When not supported the NIF
15+
// will still build, but the API functions will return {error, einval}, and
16+
// we'd fallback to the regular file API then
17+
//
18+
#if !defined(_WIN32) && defined(__LP64__)
19+
#define COUCH_CFILE_SUPPORTED 1
20+
#endif
21+
22+
#ifdef COUCH_CFILE_SUPPORTED
1523

1624
#include <errno.h>
1725
#include <limits.h>
@@ -225,7 +233,7 @@ int efile_datasync(int fd, posix_errno_t* res_errno) {
225233
//
226234
static ERL_NIF_TERM dup_nif(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
227235
{
228-
#ifndef _WIN32
236+
#ifdef COUCH_CFILE_SUPPORTED
229237
int fd, newfd;
230238
handle_t* hdl;
231239
ErlNifRWLock *lock;
@@ -293,7 +301,7 @@ static ERL_NIF_TERM dup_nif(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
293301

294302
static ERL_NIF_TERM close_nif(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
295303
{
296-
#ifndef _WIN32
304+
#ifdef COUCH_CFILE_SUPPORTED
297305
handle_t* hdl;
298306

299307
if (argc != 1 || !get_handle(env, argv[0], &hdl)) {
@@ -326,7 +334,7 @@ static ERL_NIF_TERM close_nif(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[
326334
//
327335
static ERL_NIF_TERM close_fd_nif(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
328336
{
329-
#ifndef _WIN32
337+
#ifdef COUCH_CFILE_SUPPORTED
330338
int fd;
331339

332340
if (argc != 1 || !enif_is_number(env, argv[0])) {
@@ -351,7 +359,7 @@ static ERL_NIF_TERM close_fd_nif(ErlNifEnv *env, int argc, const ERL_NIF_TERM ar
351359
//
352360
static ERL_NIF_TERM pread_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
353361
{
354-
#ifndef _WIN32
362+
#ifdef COUCH_CFILE_SUPPORTED
355363
handle_t* hdl;
356364
long offset, block_size, bytes_read;
357365
SysIOVec io_vec[1];
@@ -413,7 +421,7 @@ static ERL_NIF_TERM pread_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[
413421
// Follows implementation from prim_file_nif.c
414422
//
415423
static ERL_NIF_TERM write_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) {
416-
#ifndef _WIN32
424+
#ifdef COUCH_CFILE_SUPPORTED
417425
handle_t* hdl;
418426
ErlNifIOVec vec, *input = &vec;
419427
posix_errno_t res_errno = 0;
@@ -452,7 +460,7 @@ static ERL_NIF_TERM write_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[
452460
}
453461

454462
static ERL_NIF_TERM seek_nif(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
455-
#ifndef _WIN32
463+
#ifdef COUCH_CFILE_SUPPORTED
456464
handle_t* hdl;
457465
long result, offset;
458466
int whence;
@@ -502,7 +510,7 @@ static ERL_NIF_TERM seek_nif(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]
502510
}
503511

504512
static ERL_NIF_TERM datasync_nif(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
505-
#ifndef _WIN32
513+
#ifdef COUCH_CFILE_SUPPORTED
506514
handle_t* hdl;
507515
posix_errno_t res_errno = 0;
508516

@@ -530,7 +538,7 @@ static ERL_NIF_TERM datasync_nif(ErlNifEnv *env, int argc, const ERL_NIF_TERM ar
530538
}
531539

532540
static ERL_NIF_TERM truncate_nif(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
533-
#ifndef _WIN32
541+
#ifdef COUCH_CFILE_SUPPORTED
534542
handle_t* hdl;
535543
off_t offset;
536544

@@ -568,7 +576,7 @@ static ERL_NIF_TERM truncate_nif(ErlNifEnv *env, int argc, const ERL_NIF_TERM ar
568576
//
569577
static ERL_NIF_TERM info_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
570578
{
571-
#ifndef _WIN32
579+
#ifdef COUCH_CFILE_SUPPORTED
572580
handle_t* hdl;
573581
int fd, old_fd;
574582

@@ -601,7 +609,7 @@ static ERL_NIF_TERM info_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]
601609
//
602610
static ERL_NIF_TERM eof_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
603611
{
604-
#ifndef _WIN32
612+
#ifdef COUCH_CFILE_SUPPORTED
605613
handle_t* hdl;
606614
struct stat data;
607615

0 commit comments

Comments
 (0)