X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=doc%2Fhelp%2Fapi-filedir.html;h=45f5e33fca70a8e89ddf02fb7f60dba1a96b0d53;hb=22c9029b44a790ba1ee894027431dcea1ec2aeab;hp=107ef7906033fc3ef28d2099762f946075050e8b;hpb=b423cd4cb9fa8cf030cc046a59c28196f3edf6b4;p=thirdparty%2Fcups.git diff --git a/doc/help/api-filedir.html b/doc/help/api-filedir.html index 107ef7906..45f5e33fc 100644 --- a/doc/help/api-filedir.html +++ b/doc/help/api-filedir.html @@ -1,694 +1,995 @@ - + - File and Directory APIs - - - + File and Directory APIs + + + + +
+ + +

File and Directory APIs

+ +
+ + + + + + + + + + + + + + + + +
Headerscups/file.h
+ cups/dir.h
Library-lcups
See AlsoProgramming: Introduction to CUPS Programming
+ Programming: CUPS API
+

Contents

+ -

Introduction

+

Overview

The CUPS file and directory APIs provide portable interfaces for manipulating files and listing files and directories. Unlike -stdio FILE streams, the cupsFile functions +stdio FILE streams, the cupsFile functions allow you to open more than 256 files at any given time. They also manage the platform-specific details of locking, large file support, line endings (CR, LF, or CR LF), and reading and writing files using Flate ("gzip") compression. Finally, you can also connect, read from, and write to network connections using the -cupsFile functions.

+cupsFile functions.

-

The cupsDir functions manage the platform-specific +

The cupsDir functions manage the platform-specific details of directory access/listing and provide a convenient way to get both a list of files and the information (permissions, size, timestamp, etc.) for each of those files.

+

Functions

+

 CUPS 1.2/Mac OS X 10.5 cupsDirClose

+

Close a directory.

+

+void cupsDirClose (
+    cups_dir_t *dp
+);

+

Parameters

+
+
dp
+
Directory pointer
+
+

 CUPS 1.2/Mac OS X 10.5 cupsDirOpen

+

Open a directory.

+

+cups_dir_t *cupsDirOpen (
+    const char *directory
+);

+

Parameters

+
+
directory
+
Directory name
+
+

Return Value

+

Directory pointer or NULL if the directory could not be opened.

+

 CUPS 1.2/Mac OS X 10.5 cupsDirRead

+

Read the next directory entry.

+

+cups_dentry_t *cupsDirRead (
+    cups_dir_t *dp
+);

+

Parameters

+
+
dp
+
Directory pointer
+
+

Return Value

+

Directory entry or NULL when there are no more

+

 CUPS 1.2/Mac OS X 10.5 cupsDirRewind

+

Rewind to the start of the directory.

+

+void cupsDirRewind (
+    cups_dir_t *dp
+);

+

Parameters

+
+
dp
+
Directory pointer
+
+

 CUPS 1.2/Mac OS X 10.5 cupsFileClose

+

Close a CUPS file.

+

+int cupsFileClose (
+    cups_file_t *fp
+);

+

Parameters

+
+
fp
+
CUPS file
+
+

Return Value

+

0 on success, -1 on error

+

 CUPS 1.2/Mac OS X 10.5 cupsFileCompression

+

Return whether a file is compressed.

+

+int cupsFileCompression (
+    cups_file_t *fp
+);

+

Parameters

+
+
fp
+
CUPS file
+
+

Return Value

+

CUPS_FILE_NONE or CUPS_FILE_GZIP

+

 CUPS 1.2/Mac OS X 10.5 cupsFileEOF

+

Return the end-of-file status.

+

+int cupsFileEOF (
+    cups_file_t *fp
+);

+

Parameters

+
+
fp
+
CUPS file
+
+

Return Value

+

1 on end of file, 0 otherwise

+

 CUPS 1.2/Mac OS X 10.5 cupsFileFind

+

Find a file using the specified path.

+

+const char *cupsFileFind (
+    const char *filename,
+    const char *path,
+    int executable,
+    char *buffer,
+    int bufsize
+);

+

Parameters

+
+
filename
+
File to find
+
path
+
Colon/semicolon-separated path
+
executable
+
1 = executable files, 0 = any file/dir
+
buffer
+
Filename buffer
+
bufsize
+
Size of filename buffer
+
+

Return Value

+

Full path to file or NULL if not found

+

Discussion

+

This function allows the paths in the path string to be separated by +colons (UNIX standard) or semicolons (Windows standard) and stores the +result in the buffer supplied. If the file cannot be found in any of +the supplied paths, NULL is returned. A NULL path only +matches the current directory. -

The CUPS scheduler (cupsd), mailto notifier, -and many of the CUPS API functions use these functions for -everything except console (stdin, stdout, stderr) I/O.

- -

General Usage

+

+

 CUPS 1.2/Mac OS X 10.5 cupsFileFlush

+

Flush pending output.

+

+int cupsFileFlush (
+    cups_file_t *fp
+);

+

Parameters

+
+
fp
+
CUPS file
+
+

Return Value

+

0 on success, -1 on error

+

 CUPS 1.2/Mac OS X 10.5 cupsFileGetChar

+

Get a single character from a file.

+

+int cupsFileGetChar (
+    cups_file_t *fp
+);

+

Parameters

+
+
fp
+
CUPS file
+
+

Return Value

+

Character or -1 on end of file

+

 CUPS 1.2/Mac OS X 10.5 cupsFileGetConf

+

Get a line from a configuration file.

+

+char *cupsFileGetConf (
+    cups_file_t *fp,
+    char *buf,
+    size_t buflen,
+    char **value,
+    int *linenum
+);

+

Parameters

+
+
fp
+
CUPS file
+
buf
+
String buffer
+
buflen
+
Size of string buffer
+
value
+
Pointer to value
+
linenum
+
Current line number
+
+

Return Value

+

Line read or NULL on end of file or error

+

 CUPS 1.2/Mac OS X 10.5 cupsFileGetLine

+

Get a CR and/or LF-terminated line that may +contain binary data.

+

+size_t cupsFileGetLine (
+    cups_file_t *fp,
+    char *buf,
+    size_t buflen
+);

+

Parameters

+
+
fp
+
File to read from
+
buf
+
Buffer
+
buflen
+
Size of buffer
+
+

Return Value

+

Number of bytes on line or 0 on end of file

+

Discussion

+

This function differs from cupsFileGets in that the trailing CR +and LF are preserved, as is any binary data on the line. The buffer is +nul-terminated, however you should use the returned length to determine +the number of bytes on the line. -

The <cups/dir.h> and -<cups/file.h> header files must be included to -use the cupsDir and cupsFile functions, -respectively.

+

+

 CUPS 1.2/Mac OS X 10.5 cupsFileGets

+

Get a CR and/or LF-terminated line.

+

+char *cupsFileGets (
+    cups_file_t *fp,
+    char *buf,
+    size_t buflen
+);

+

Parameters

+
+
fp
+
CUPS file
+
buf
+
String buffer
+
buflen
+
Size of string buffer
+
+

Return Value

+

Line read or NULL on end of file or error

+

 CUPS 1.2/Mac OS X 10.5 cupsFileLock

+

Temporarily lock access to a file.

+

+int cupsFileLock (
+    cups_file_t *fp,
+    int block
+);

+

Parameters

+
+
fp
+
CUPS file
+
block
+
1 to wait for the lock, 0 to fail right away
+
+

Return Value

+

0 on success, -1 on error

+

 CUPS 1.2/Mac OS X 10.5 cupsFileNumber

+

Return the file descriptor associated with a CUPS file.

+

+int cupsFileNumber (
+    cups_file_t *fp
+);

+

Parameters

+
+
fp
+
CUPS file
+
+

Return Value

+

File descriptor

+

 CUPS 1.2/Mac OS X 10.5 cupsFileOpen

+

Open a CUPS file.

+

+cups_file_t *cupsFileOpen (
+    const char *filename,
+    const char *mode
+);

+

Parameters

+
+
filename
+
Name of file
+
mode
+
Open mode
+
+

Return Value

+

CUPS file or NULL if the file or socket cannot be opened

+

Discussion

+

The "mode" parameter can be "r" to read, "w" to write, overwriting any +existing file, "a" to append to an existing file or create a new file, +or "s" to open a socket connection.
+
+When opening for writing ("w"), an optional number from 1 to 9 can be +supplied which enables Flate compression of the file. Compression is +not supported for the "a" (append) mode.
+
+When opening a socket connection, the filename is a string of the form +"address:port" or "hostname:port". The socket will make an IPv4 or IPv6 +connection as needed, generally preferring IPv6 connections when there is +a choice. -

Programs using these functions must be linked to the CUPS -library: libcups.a, libcups.so.2, -libcups.2.dylib, libcups_s.a, or -libcups2.lib depending on the platform. The following -command compiles myprogram.c using GCC and the CUPS -library:

+

+

 CUPS 1.2/Mac OS X 10.5 cupsFileOpenFd

+

Open a CUPS file using a file descriptor.

+

+cups_file_t *cupsFileOpenFd (
+    int fd,
+    const char *mode
+);

+

Parameters

+
+
fd
+
File descriptor
+
mode
+
Open mode
+
+

Return Value

+

CUPS file or NULL if the file could not be opened

+

Discussion

+

The "mode" parameter can be "r" to read, "w" to write, "a" to append, +or "s" to treat the file descriptor as a bidirectional socket connection.
+
+When opening for writing ("w"), an optional number from 1 to 9 can be +supplied which enables Flate compression of the file. Compression is +not supported for the "a" (append) mode. -

-gcc -o myprogram myprogram.c -lcups
-
+

+

 CUPS 1.2/Mac OS X 10.5 cupsFilePeekChar

+

Peek at the next character from a file.

+

+int cupsFilePeekChar (
+    cups_file_t *fp
+);

+

Parameters

+
+
fp
+
CUPS file
+
+

Return Value

+

Character or -1 on end of file

+

 CUPS 1.2/Mac OS X 10.5 cupsFilePrintf

+

Write a formatted string.

+

+int cupsFilePrintf (
+    cups_file_t *fp,
+    const char *format,
+    ...
+);

+

Parameters

+
+
fp
+
CUPS file
+
format
+
Printf-style format string
+
...
+
Additional args as necessary
+
+

Return Value

+

Number of bytes written or -1 on error

+

 CUPS 1.2/Mac OS X 10.5 cupsFilePutChar

+

Write a character.

+

+int cupsFilePutChar (
+    cups_file_t *fp,
+    int c
+);

+

Parameters

+
+
fp
+
CUPS file
+
c
+
Character to write
+
+

Return Value

+

0 on success, -1 on error

+

 CUPS 1.4/Mac OS X 10.6 cupsFilePutConf

+

Write a configuration line.

+

+ssize_t cupsFilePutConf (
+    cups_file_t *fp,
+    const char *directive,
+    const char *value
+);

+

Parameters

+
+
fp
+
CUPS file
+
directive
+
Directive
+
value
+
Value
+
+

Return Value

+

Number of bytes written or -1 on error

+

Discussion

+

This function handles any comment escaping of the value. -

Compatibility

+

+

 CUPS 1.2/Mac OS X 10.5 cupsFilePuts

+

Write a string.

+

+int cupsFilePuts (
+    cups_file_t *fp,
+    const char *s
+);

+

Parameters

+
+
fp
+
CUPS file
+
s
+
String to write
+
+

Return Value

+

Number of bytes written or -1 on error

+

Discussion

+

Like the fputs function, no newline is appended to the string. -

All of these functions require CUPS 1.2 or higher.

-

Contents

- - -

Functions

- - -

cupsDirClose()

-

Description

-

Close a directory.

-

Syntax

-
-void
-cupsDirClose(
-    cups_dir_t * dp);
-
-

Arguments

-
- - - -
NameDescription
dpDirectory
-

Returns

-

Nothing.

- -

cupsDirOpen()

-

Description

-

Open a directory.

-

Syntax

-
-cups_dir_t *
-cupsDirOpen(
-    const char * directory);
-
-

Arguments

-
- - - -
NameDescription
directoryDirectory name
-

Returns

-

Directory

- -

cupsDirRead()

-

Description

-

Read the next directory entry.

-

Syntax

-
-cups_dentry_t *
-cupsDirRead(
-    cups_dir_t * dp);
-
-

Arguments

-
- - - -
NameDescription
dpDirectory
-

Returns

-

Directory entry

- -

cupsDirRewind()

-

Description

-

Rewind to the start of the directory.

-

Syntax

-
-void
-cupsDirRewind(
-    cups_dir_t * dp);
-
-

Arguments

-
- - - -
NameDescription
dpDirectory
-

Returns

-

Nothing.

- -

cupsFileClose()

-

Description

-

Close a CUPS file.

-

Syntax

-
-int
-cupsFileClose(
-    cups_file_t * fp);
-
-

Arguments

-
- - - -
NameDescription
fpCUPS file
-

Returns

-

0 on success, -1 on error

- -

cupsFileCompression()

-

Description

-

Return whether a file is compressed.

-

Syntax

-
-int
-cupsFileCompression(
-    cups_file_t * fp);
-
-

Arguments

-
- - - -
NameDescription
fpCUPS file
-

Returns

-

CUPS_FILE_NONE or CUPS_FILE_GZIP

- -

cupsFileEOF()

-

Description

-

Return the end-of-file status.

-

Syntax

-
-int
-cupsFileEOF(
-    cups_file_t * fp);
-
-

Arguments

-
- - - -
NameDescription
fpCUPS file
-

Returns

-

1 on EOF, 0 otherwise

- -

cupsFileFind()

-

Description

-

Find a file using the specified path. - -This function allows the paths in the path string to be separated by -colons (UNIX standard) or semicolons (Windows standard) and stores the -result in the buffer supplied. If the file cannot be found in any of -the supplied paths, NULL is returned. A NULL path only matches the -current directory.

-

Syntax

-
-const char *
-cupsFileFind(
-    const char * filename,
-    const char * path,
-    int executable,
-    char * buffer,
-    int bufsize);
-
-

Arguments

-
- - - - - - - -
NameDescription
filenameFile to find
pathColon/semicolon-separated path
executable1 = executable files, 0 = any file/dir
bufferFilename buffer
bufsizeSize of filename buffer
-

Returns

-

Full path to file or NULL

- -

cupsFileFlush()

-

Description

-

Flush pending output.

-

Syntax

-
-int
-cupsFileFlush(
-    cups_file_t * fp);
-
-

Arguments

-
- - - -
NameDescription
fpCUPS file
-

Returns

-

0 on success, -1 on error

- -

cupsFileGetChar()

-

Description

-

Get a single character from a file.

-

Syntax

-
-int
-cupsFileGetChar(
-    cups_file_t * fp);
-
-

Arguments

-
- - - -
NameDescription
fpCUPS file
-

Returns

-

Character or -1 on EOF

- -

cupsFileGetConf()

-

Description

-

Get a line from a configuration file...

-

Syntax

-
-char *
-cupsFileGetConf(
-    cups_file_t * fp,
-    char * buf,
-    size_t buflen,
-    char ** value,
-    int * linenum);
-
-

Arguments

-
- - - - - - - -
NameDescription
fpCUPS file
bufString buffer
buflenSize of string buffer
valuePointer to value
linenumCurrent line number
-

Returns

-

Line read or NULL on eof/error

- -

cupsFileGets()

-

Description

-

Get a CR and/or LF-terminated line.

-

Syntax

-
-char *
-cupsFileGets(
-    cups_file_t * fp,
-    char * buf,
-    size_t buflen);
-
-

Arguments

-
- - - - - -
NameDescription
fpCUPS file
bufString buffer
buflenSize of string buffer
-

Returns

-

Line read or NULL on eof/error

- -

cupsFileLock()

-

Description

-

Temporarily lock access to a file.

-

Syntax

-
-int
-cupsFileLock(
-    cups_file_t * fp,
-    int block);
-
-

Arguments

-
- - - - -
NameDescription
fpFile to lock
block1 to wait for the lock, 0 to fail right away
-

Returns

-

0 on success, -1 on error

- -

cupsFileNumber()

-

Description

-

Return the file descriptor associated with a CUPS file.

-

Syntax

-
-int
-cupsFileNumber(
-    cups_file_t * fp);
-
-

Arguments

-
- - - -
NameDescription
fpCUPS file
-

Returns

-

File descriptor

- -

cupsFileOpen()

-

Description

-

Open a CUPS file.

-

Syntax

-
-cups_file_t *
-cupsFileOpen(
-    const char * filename,
-    const char * mode);
-
-

Arguments

-
- - - - -
NameDescription
filenameName of file
modeOpen mode
-

Returns

-

CUPS file or NULL

- -

cupsFileOpenFd()

-

Description

-

Open a CUPS file using a file descriptor.

-

Syntax

-
-cups_file_t *
-cupsFileOpenFd(
-    int fd,
-    const char * mode);
-
-

Arguments

-
- - - - -
NameDescription
fdFile descriptor
modeOpen mode
-

Returns

-

CUPS file or NULL

- -

cupsFilePeekChar()

-

Description

-

Peek at the next character from a file.

-

Syntax

-
-int
-cupsFilePeekChar(
-    cups_file_t * fp);
-
-

Arguments

-
- - - -
NameDescription
fpCUPS file
-

Returns

-

Character or -1 on EOF

- -

cupsFilePrintf()

-

Description

-

Write a formatted string.

-

Syntax

-
-int
-cupsFilePrintf(
-    cups_file_t * fp,
-    const char * format,
-    ...);
-
-

Arguments

-
- - - - - -
NameDescription
fpCUPS file
formatPrintf-style format string
...Additional args as necessary
-

Returns

-

Number of bytes written or -1

- -

cupsFilePutChar()

-

Description

-

Write a character.

-

Syntax

-
-int
-cupsFilePutChar(
-    cups_file_t * fp,
-    int c);
-
-

Arguments

-
- - - - -
NameDescription
fpCUPS file
cCharacter to write
-

Returns

-

0 on success, -1 on error

- -

cupsFilePuts()

-

Description

-

Write a string.

-

Syntax

-
-int
-cupsFilePuts(
-    cups_file_t * fp,
-    const char * s);
-
-

Arguments

-
- - - - -
NameDescription
fpCUPS file
sString to write
-

Returns

-

Number of bytes written or -1

- -

cupsFileRead()

-

Description

-

Read from a file.

-

Syntax

-
-ssize_t
-cupsFileRead(
-    cups_file_t * fp,
-    char * buf,
-    size_t bytes);
-
-

Arguments

-
- - - - - -
NameDescription
fpCUPS file
bufBuffer
bytesNumber of bytes to read
-

Returns

-

Number of bytes read or -1

- -

cupsFileRewind()

-

Description

-

Rewind a file.

-

Syntax

-
-off_t
-cupsFileRewind(
-    cups_file_t * fp);
-
-

Arguments

-
- - - -
NameDescription
fpCUPS file
-

Returns

-

New file position or -1

- -

cupsFileSeek()

-

Description

-

Seek in a file.

-

Syntax

-
-off_t
-cupsFileSeek(
-    cups_file_t * fp,
-    off_t pos);
-
-

Arguments

-
- - - - -
NameDescription
fpCUPS file
posPosition in file
-

Returns

-

New file position or -1

- -

cupsFileTell()

-

Description

-

Return the current file position.

-

Syntax

-
-off_t
-cupsFileTell(
-    cups_file_t * fp);
-
-

Arguments

-
- - - -
NameDescription
fpCUPS file
-

Returns

-

File position

- -

cupsFileUnlock()

-

Description

-

Unlock access to a file.

-

Syntax

-
-int
-cupsFileUnlock(
-    cups_file_t * fp);
-
-

Arguments

-
- - - -
NameDescription
fpFile to lock
-

Returns

-

0 on success, -1 on error

- -

cupsFileWrite()

-

Description

-

Write to a file.

-

Syntax

-
-ssize_t
-cupsFileWrite(
-    cups_file_t * fp,
-    const char * buf,
-    size_t bytes);
-
-

Arguments

-
- - - - - -
NameDescription
fpCUPS file
bufBuffer
bytesNumber of bytes to write
-

Returns

-

Number of bytes written

- -

Structures

- - -

cups_dentry_s

-

Description

-

Directory entry type

-

Definition

-
-struct cups_dentry_s
-{
-  struct stat fileinfo;
-  char filename[260];
-};
-
-

Members

-
- - - - -
NameDescription
fileinfo File information
filename[260] File name
- -

Types

- - -

cups_dentry_t

-

Description

-

Directory entry type

-

Definition

-
-typedef struct cups_dentry_s cups_dentry_t;
-
- -

cups_dir_t

-

Description

-

Directory type

-

Definition

-
+

+

 CUPS 1.2/Mac OS X 10.5 cupsFileRead

+

Read from a file.

+

+ssize_t cupsFileRead (
+    cups_file_t *fp,
+    char *buf,
+    size_t bytes
+);

+

Parameters

+
+
fp
+
CUPS file
+
buf
+
Buffer
+
bytes
+
Number of bytes to read
+
+

Return Value

+

Number of bytes read or -1 on error

+

 CUPS 1.2/Mac OS X 10.5 cupsFileRewind

+

Set the current file position to the beginning of the +file.

+

+off_t cupsFileRewind (
+    cups_file_t *fp
+);

+

Parameters

+
+
fp
+
CUPS file
+
+

Return Value

+

New file position or -1 on error

+

 CUPS 1.2/Mac OS X 10.5 cupsFileSeek

+

Seek in a file.

+

+off_t cupsFileSeek (
+    cups_file_t *fp,
+    off_t pos
+);

+

Parameters

+
+
fp
+
CUPS file
+
pos
+
Position in file
+
+

Return Value

+

New file position or -1 on error

+

 CUPS 1.2/Mac OS X 10.5 cupsFileStderr

+

Return a CUPS file associated with stderr.

+

+cups_file_t *cupsFileStderr (void);

+

Return Value

+

CUPS file

+

 CUPS 1.2/Mac OS X 10.5 cupsFileStdin

+

Return a CUPS file associated with stdin.

+

+cups_file_t *cupsFileStdin (void);

+

Return Value

+

CUPS file

+

 CUPS 1.2/Mac OS X 10.5 cupsFileStdout

+

Return a CUPS file associated with stdout.

+

+cups_file_t *cupsFileStdout (void);

+

Return Value

+

CUPS file

+

 CUPS 1.2/Mac OS X 10.5 cupsFileTell

+

Return the current file position.

+

+off_t cupsFileTell (
+    cups_file_t *fp
+);

+

Parameters

+
+
fp
+
CUPS file
+
+

Return Value

+

File position

+

 CUPS 1.2/Mac OS X 10.5 cupsFileUnlock

+

Unlock access to a file.

+

+int cupsFileUnlock (
+    cups_file_t *fp
+);

+

Parameters

+
+
fp
+
CUPS file
+
+

Return Value

+

0 on success, -1 on error

+

 CUPS 1.2/Mac OS X 10.5 cupsFileWrite

+

Write to a file.

+

+ssize_t cupsFileWrite (
+    cups_file_t *fp,
+    const char *buf,
+    size_t bytes
+);

+

Parameters

+
+
fp
+
CUPS file
+
buf
+
Buffer
+
bytes
+
Number of bytes to write
+
+

Return Value

+

Number of bytes written or -1 on error

+

Data Types

+

cups_dentry_t

+

Directory entry type

+

+typedef struct cups_dentry_s cups_dentry_t; +

+

cups_dir_t

+

Directory type

+

typedef struct _cups_dir_s cups_dir_t; -

- -

cups_file_t

-

Description

-

CUPS file type

-

Definition

-
+

+

cups_file_t

+

CUPS file type

+

typedef struct _cups_file_s cups_file_t; -

+

+

Structures

+

cups_dentry_s

+

Directory entry type

+

struct cups_dentry_s {
+    struct stat fileinfo;
+    char filename[260];
+};

+

Members

+
+
fileinfo
+
File information
+
filename[260]
+
File name
+
+