2020-06-03 18:40:05 -04:00
|
|
|
// 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
|
2020-01-25 15:04:11 -05:00
|
|
|
|
|
|
|
#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) {
|
2021-03-15 09:57:36 -04:00
|
|
|
#ifndef _MSC_VER
|
2020-01-25 15:04:11 -05:00
|
|
|
_fmode = mode;
|
|
|
|
return 0;
|
2021-03-15 09:57:36 -04:00
|
|
|
#else
|
2020-01-25 15:04:11 -05:00
|
|
|
return _set_fmode(mode);
|
2021-03-15 09:57:36 -04:00
|
|
|
#endif
|
2020-01-25 15:04:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void set_fmode_binary(void) {
|
|
|
|
set_fmode_impl(O_BINARY);
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_fmode_text(void) {
|
|
|
|
set_fmode_impl(O_TEXT);
|
|
|
|
}
|