Skip to content

Commit ed77585

Browse files
Moved O_BINARY definition into new nvme/fcntl.h
1 parent 7d28895 commit ed77585

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

libnvme/src/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ endif
3232
headers = [
3333
'nvme/accessors.h',
3434
'nvme/endian.h',
35+
'nvme/fcntl.h',
3536
'nvme/filters.h',
3637
'nvme/ioctl.h',
3738
'nvme/lib-types.h',

libnvme/src/nvme/fcntl.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2+
/*
3+
* This file is part of libnvme.
4+
* Copyright (c) 2026 Micron Technology, Inc.
5+
*
6+
* Cross-platform compatibility for fcntl.h.
7+
*
8+
* Authors: Broc Going <[email protected]>
9+
*/
10+
#pragma once
11+
12+
#include <fcntl.h>
13+
14+
/*
15+
* O_BINARY is required for Windows to avoid line ending translations.
16+
* Define it as 0 on platforms where it is not defined so that it can be used
17+
* but will have no effect.
18+
*/
19+
#ifndef O_BINARY
20+
#define O_BINARY 0
21+
#endif

plugins/ocp/ocp-nvme.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <time.h>
1818

1919
#include <libnvme.h>
20+
#include <nvme/fcntl.h>
2021

2122
#include "common.h"
2223
#include "logging.h"
@@ -1188,11 +1189,7 @@ static int get_telemetry_log_page_data(struct libnvme_transport_handle *hdl,
11881189
}
11891190
memset(hdr, 0, bs);
11901191

1191-
#ifdef O_BINARY /* required for Windows, not defined on Linux */
11921192
fd = open(output_file, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666);
1193-
#else
1194-
fd = open(output_file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
1195-
#endif
11961193
if (fd < 0) {
11971194
fprintf(stderr, "Failed to open output file %s: %s!\n",
11981195
output_file, libnvme_strerror(errno));

0 commit comments

Comments
 (0)