Read, Read_error_code – Argox PA-20 Programming Guide User Manual

Page 45

Advertising
background image

PT-20 Programming Guide

43

and an error code is set to the global variable

fErrorCode to indicate the error condition encountered. Possible

error codes and their interpretation are listed below.

fErrorCode: 1:filename is a NULL string.

6:Can't create file. Because the maximum number of files allowed in the

system is exceeded.

read

Purpose: Read a specified number of bytes from a DAT file.

Syntax: int read(int fd, char *buffer, unsigned count);

Example call: if ((bytes_read = read(fd,buffer,50)) = = -1)

_puts(“read error!”);

Includes:

#include “SDK.h ”

Description: The read function copies the number of bytes specified in the

argument count from the DAT file whose file handle is fd to the

array of characters buffer. Reading starts at the current position of

the file pointer, which is incremented accordingly when the

operation is completed.

Returns: The read function returns the number of bytes actually read from

the file. In case of error, read returns an integer value of -1 and an

error code is set to the global variable fErrorCode to indicate the

error condition encountered. Possible error codes and their

interpretation are listed below.

fErrorCode: 2:File handle is NULL.

7:fd is not a file handle of a previously opened file.

read_error_code

Purpose: Get the value of the global variable fErrorCode.

Syntax: int read_error_code( );

Example call:

if (read_error_code( ) = = 2) _puts(“File not exist!”);

Includes:

#include “SDK.h ”

Description: The read_error_code function gets the value of the global variable

fErrorCode and returns the value to the calling program. The

programmer can use this function to get the error code of the file

manipulation routine previously called. However, the global

variable fErrorCode can be directly accessed without making a

call to this function.

Returns: The read_error_code function returns the value of the global

variable fErrorCode.

fErrorCode: None

Advertising