Skip to content

Commit ae2f606

Browse files
authored
mmap : fix fileno macro clash (#11076)
* mmap : fix fileno macro clash ggml-ci * cont ggml-ci
1 parent 727368c commit ae2f606

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/llama-mmap.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,16 @@ llama_file::~llama_file() = default;
241241
size_t llama_file::tell() const { return pimpl->tell(); }
242242
size_t llama_file::size() const { return pimpl->size; }
243243

244-
int llama_file::fileno() const {
244+
int llama_file::file_id() const {
245245
#ifdef _WIN32
246246
return _fileno(pimpl->fp);
247+
#else
248+
#if defined(fileno)
249+
return fileno(pimpl->fp);
247250
#else
248251
return ::fileno(pimpl->fp);
249252
#endif
253+
#endif
250254
}
251255

252256
void llama_file::seek(size_t offset, int whence) const { pimpl->seek(offset, whence); }
@@ -265,7 +269,7 @@ struct llama_mmap::impl {
265269

266270
impl(struct llama_file * file, size_t prefetch, bool numa) {
267271
size = file->size();
268-
int fd = file->fileno();
272+
int fd = file->file_id();
269273
int flags = MAP_SHARED;
270274
if (numa) { prefetch = 0; }
271275
#ifdef __linux__
@@ -357,7 +361,7 @@ struct llama_mmap::impl {
357361

358362
size = file->size();
359363

360-
HANDLE hFile = (HANDLE) _get_osfhandle(file->fileno());
364+
HANDLE hFile = (HANDLE) _get_osfhandle(file->file_id());
361365

362366
HANDLE hMapping = CreateFileMappingA(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
363367

src/llama-mmap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct llama_file {
1818
size_t tell() const;
1919
size_t size() const;
2020

21-
int fileno() const;
21+
int file_id() const; // fileno overload
2222

2323
void seek(size_t offset, int whence) const;
2424

0 commit comments

Comments
 (0)