1
0
mirror of https://github.com/arsenetar/send2trash.git synced 2024-10-29 21:05:57 +00:00
send2trash/modules/send2trash_osx.c
Virgil Dupras 8a1dff2947 Renamed _trash_* modules to _send2trash_* and added python wrapper around them.
--HG--
rename : modules/trash_osx.c => modules/send2trash_osx.c
rename : modules/trash_win.c => modules/send2trash_win.c
2010-04-06 18:04:32 +02:00

37 lines
894 B
C

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include <CoreServices/CoreServices.h>
static PyObject* send2trash_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_OSError, GetMacOSStatusCommentString(op_result));
return NULL;
}
return Py_None;
}
static PyMethodDef TrashMethods[] = {
{"send", send2trash_osx_send, METH_VARARGS, ""},
};
PyMODINIT_FUNC
init_send2trash_osx(void)
{
PyObject *m = Py_InitModule("_send2trash_osx", TrashMethods);
if (m == NULL) {
return;
}
}