Trouble understanding how to process C string

后端 未结 4 1410
粉色の甜心
粉色の甜心 2021-01-27 07:13

I\'m trying to use Mac OS X\'s listxattr C function and turn it into something useful in Python. The man page tells me that the function returns a string buffer, which is a \"si

4条回答
  •  青春惊慌失措
    2021-01-27 07:40

    Actually, since I'm going to send it to Python I don't have to process it C-style after all. Just use the Py_BuildValue passing it the format character s#, which knows what do with it. You'll also need the size.

    return Py_BuildValue("s#", buffer, size);
    

    You can process it into a list on Python's end using split('\x00'). I found this after trial and error, but I'm glad to have learned something about C.

提交回复
热议问题