0x00sec_JINX

CExtenmodule.c

Jun 8th, 2016
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.97 KB | None | 0 0
  1. #include <Python.h> //Python dev module
  2.  
  3. // Define a function
  4. static PyObject* CExten_CCat(PyObject* self, PyObject* args){
  5.    
  6.    const char* file_path;
  7.    FILE* fd;
  8.    char chunk[128];
  9.  
  10.    //parsing the arguments (only if needed)
  11.    if(!PyArg_ParseTuple(args, "s", &file_path)){
  12.       return NULL; //send error to the python interpreter
  13.    }
  14.    
  15.    if((fd = fopen(file_path,"r")) < 0){
  16.       return NULL;
  17.    }
  18.  
  19.    while((fgets(chunk,sizeof(chunk),(FILE*)fd)) != NULL){
  20.       printf("%s",chunk);
  21.    }
  22.  
  23.    printf("\n");
  24.    fclose(fd);
  25.  
  26.    Py_INCREF(Py_None);
  27.    return Py_None;
  28.  
  29. }
  30. static PyMethodDef CExten_methods[] = {
  31.     //Python Func Name    C Func Name    Arg Count        Description
  32.     {"CCat",              CExten_CCat,   METH_VARARGS,    NULL},
  33.     {NULL,NULL,0,NULL}    //ending sentinel
  34. };
  35.  
  36. PyMODINIT_FUNC initCExten(void){
  37.     PyObject *m;
  38.     m = Py_InitModule("CExten",CExten_methods);
  39.     if(m == NULL){
  40.         return;
  41.     }
  42. }
Add Comment
Please, Sign In to add comment