Download presentation
Presentation is loading. Please wait.
1
Network Programming CSC- 341
Instructor: Junaid Tariq, Lecturer, Department of Computer Science
2
13 Lecture Network Programming
3
3.9 readn, writen, and realine Functions
#include “unp.h” ssize_t readn(int filedes, void *buff, size_t nbytes); ssize_t writen(int filedes, const void *buff, size_t nbytes); ssize_t readline(int filedes, void *buff, size_t maxline); All return: number of bytes read or written, -1 on error
4
Readn()
5
writen
6
readline
7
3.10 Isfdtype function Test a Descriptor to see if it is of a specified type historically : fstat function used ==> testing the returned value st_mode value using one of the S_IFxxx macro. #include <sys/stat.h> int isfdtype(int fd, int fdtype); /* return:1 if descriptor of specified type, 0 if not, -1 on error */ /* To test for a socket, fdtype is S_IFSOCK.*/
8
#ifndef S_IFSOCK #error S_IFSOCK not defined #endif int isfdtype(int fd, int fdtype) { struct stat buf; if(fstat (fd, &buf) < 0) return (-1); if((buf.st_mode & S_IFMT) == fdtype) return (1); else return (0); }
9
st_mode field The following flags are defined for the st_mode field:
S_IFMT bit mask for the file type bit fields S_IFSOCK socket S_IFLNK symbolic link S_IFREG regular file S_IFBLK block device S_IFDIR directory S_IFCHR character device S_IFIFO FIFO
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.