-
-
Notifications
You must be signed in to change notification settings - Fork 23
Fixed ringtone saving #197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
40d2d6b
a5e3c73
08d0779
b5d4976
8a41e90
52427ba
2daacd8
1ef64c8
cbf772b
083db8d
46bdc0d
1ffa03c
5575449
d77bd6b
8ca79a9
da74ed7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,13 @@ | |
| /* Locales */ | ||
| #include <locale.h> | ||
|
|
||
| /* File creation and permissions */ | ||
| #include <sys/stat.h> | ||
| #include <fcntl.h> | ||
| #ifdef _WIN32 | ||
| #include <io.h> | ||
| #endif | ||
|
|
||
| /* Strings */ | ||
| #ifdef HAVE_STRING_H | ||
| #include <string.h> | ||
|
|
@@ -6070,7 +6077,7 @@ gammu_SaveRingtone(PyObject *self, PyObject *args, PyObject *kwds) | |
| return NULL; | ||
| } | ||
|
|
||
| fd = PyObject_AsFileDescriptor(value); | ||
| fd = PyObject_AsFileDescriptor(file); | ||
| if (fd == -1) { | ||
| PyErr_Clear(); | ||
| } | ||
|
|
@@ -6081,16 +6088,37 @@ gammu_SaveRingtone(PyObject *self, PyObject *args, PyObject *kwds) | |
| f = fdopen(fd, "wb"); | ||
| if (f == NULL) return NULL; | ||
| closefile = TRUE; | ||
| } else if (PyUnicode_Check(value)) { | ||
| str = PyUnicode_EncodeFSDefault(value); | ||
| } else if (PyUnicode_Check(file)) { | ||
| int ofd; | ||
|
|
||
| str = PyUnicode_EncodeFSDefault(file); | ||
| if (str == NULL) { | ||
| return NULL; | ||
| } | ||
| name = PyBytes_AsString(str); | ||
| if (name == NULL) return NULL; | ||
| f = fopen(name, "wb"); | ||
| if (name == NULL) { | ||
| Py_DECREF(str); | ||
| return NULL; | ||
| } | ||
| #ifdef _WIN32 | ||
| /* Windows: use _open with _S_IREAD | _S_IWRITE for owner read/write */ | ||
| ofd = _open(name, _O_WRONLY | _O_CREAT | _O_TRUNC | _O_BINARY, _S_IREAD | _S_IWRITE); | ||
| #else | ||
| /* POSIX: use open with S_IRUSR | S_IWUSR for owner read/write */ | ||
| ofd = open(name, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); | ||
| #endif | ||
| Py_DECREF(str); | ||
| if (ofd == -1) { | ||
| PyErr_SetString(PyExc_IOError, "Can not open file for writing!"); | ||
| return NULL; | ||
| } | ||
| f = fdopen(ofd, "wb"); | ||
| if (f == NULL) { | ||
| #ifdef _WIN32 | ||
| _close(ofd); | ||
| #else | ||
| close(ofd); | ||
|
Comment on lines
+6108
to
+6120
|
||
| #endif | ||
| PyErr_SetString(PyExc_IOError, "Can not open file for writing!"); | ||
| return NULL; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The headers
<fcntl.h>and<sys/stat.h>are POSIX headers that are not available on Windows. Since this project supports Windows builds (as evidenced by the CI workflows), these includes should be wrapped in platform-specific guards or replaced with Windows-compatible alternatives.For Windows compatibility, consider using
<io.h>and<sys/stat.h>(Windows has a limited version) with appropriate#ifdef _WIN32guards.