Tested this both on Ubuntu and ArchLinux, I get
from ctypes import *
libc = CDLL('libc.so.6')
libc.environ()
Segmentation fault
Why?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If i read the manpage correctly,
environis achar**, not a function.If you want to get the environ var, according to this post, you could do:
But it return ‘c_void_p(None)’ for me, not sure why this happening (i know that i’ve declared as a
char *only, but since it is returning None, their is nothing to dereference).Anyway, you still have the “python” way:
Or, if you search for a specific string in the environ using ctypes, for some function, you need to redefined the default restype: