aboutsummaryrefslogtreecommitdiff
path: root/circuitpython/mpy-cross/fmode.c
blob: f32a4af5d335bdaf7f56d295c86b991522ee203e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// SPDX-FileCopyrightText: Copyright (c) 2013-2016 Damien P. George
// SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)
//
// SPDX-License-Identifier: MIT

#include "fmode.h"
#include "py/mpconfig.h"
#include <fcntl.h>
#include <stdlib.h>

// Workaround for setting file translation mode: we must distinguish toolsets
// since mingw has no _set_fmode, and altering msvc's _fmode directly has no effect
STATIC int set_fmode_impl(int mode) {
    #ifndef _MSC_VER
    _fmode = mode;
    return 0;
    #else
    return _set_fmode(mode);
    #endif
}

void set_fmode_binary(void) {
    set_fmode_impl(O_BINARY);
}

void set_fmode_text(void) {
    set_fmode_impl(O_TEXT);
}