mirror of
https://github.com/arsenetar/send2trash.git
synced 2026-01-22 22:51:39 +00:00
Added the osx module.
This commit is contained in:
36
modules/trash_osx.c
Normal file
36
modules/trash_osx.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#define PY_SSIZE_T_CLEAN
|
||||
#include "Python.h"
|
||||
#include <CoreServices/CoreServices.h>
|
||||
|
||||
static PyObject* trash_osx_send(PyObject *self, PyObject *args)
|
||||
{
|
||||
UInt8 *utf8_chars;
|
||||
FSRef fp;
|
||||
OSStatus op_result;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "es", "utf-8", &utf8_chars)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
FSPathMakeRefWithOptions(utf8_chars, kFSPathMakeRefDoNotFollowLeafSymlink, &fp, NULL);
|
||||
op_result = FSMoveObjectToTrashSync(&fp, NULL, kFSFileOperationDefaultOptions);
|
||||
if (op_result != noErr) {
|
||||
PyErr_SetString(PyExc_IOError, GetMacOSStatusCommentString(op_result));
|
||||
return NULL;
|
||||
}
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyMethodDef TrashMethods[] = {
|
||||
{"send", trash_osx_send, METH_VARARGS, ""},
|
||||
};
|
||||
|
||||
PyMODINIT_FUNC
|
||||
init_trash_osx(void)
|
||||
{
|
||||
PyObject *m = Py_InitModule("_trash_osx", TrashMethods);
|
||||
if (m == NULL) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user