Python3 os.fpathconf() Method
os.fpathconf Overview
The os.fpathconf() method is used to return the system configuration information for an open file.
Available on Unix/Linux.
os.fpathconf Syntax
The syntax format of the fpathconf() method is as follows.
os.fpathconf(fd, name)
os.fpathconf Parameters
- fd – The descriptor of the open file.
- name – Optional, like the buffersize argument and Python’s built-in open function, the mode argument can specify ‘r,w,a,r+,w+,a+,b’, etc. indicating whether the file is read-only or read-write, and whether the file is opened in binary or text form. These parameters are similar to the mode parameters specified in the fopen function in
in C language.
os.fpathconf Return Value
Returns the system configuration information for an open file.
os.fpathconf Demo
The following example demonstrates the use of the fpathconf() method:
#!/usr/bin/python3
import os, sys
# Open file
fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )
print ("%s" % os.pathconf_names)
# Get the maximum number of file connections
no = os.fpathconf(fd, 'PC_LINK_MAX')
print ("The maximum number of connections to the file is :%d" % no)
# Get the maximum length of the file name
no = os.fpathconf(fd, 'PC_NAME_MAX')
print ("The maximum length of the file name is :%d" % no)
# Close file
os.close( fd )
print ("Closed the file successfully!!")
The output of executing the above program is:
{'PC_MAX_INPUT': 2, 'PC_VDISABLE': 8, 'PC_SYNC_IO': 9,
'PC_SOCK_MAXBUF': 12, 'PC_NAME_MAX': 3, 'PC_MAX_CANON': 1,
'PC_PRIO_IO': 11, 'PC_CHOWN_RESTRICTED': 6, 'PC_ASYNC_IO': 10,
'PC_NO_TRUNC': 7, 'PC_FILESIZEBITS': 13, 'PC_LINK_MAX': 0,
'PC_PIPE_BUF': 5, 'PC_PATH_MAX': 4}
The maximum number of connections to the file is :127
The maximum length of the file name is :255
Closed the file successfully!!