The setservent(3) function allows you to rewind the file that is opened behind the scenes in the function getservent(3). For example, if you were to try to process entries a second time in Listing 7.2, you would need setservent(3) to rewind to the start of the /etc/services file. Otherwise, you will just continue to receive end-of-file indications. The function synopsis is as follows:
void setservent(int stayopen);
This function takes one argument, which is a Boolean value:
- When non-zero (TRUE), the stayopen argument indicates that the file should be rewound instead of re-opened when rereading the /etc/services file is performed. This is preferred for performance reasons.
- When zero (FALSE), the file is closed if it has been previously opened (by getservent(3), for example). Then the function re-opens the file to make ready for the next getservent(3) call. There is no return value for this function.
Post a Comment