United States    
COMPAQ STORE | PRODUCTS |
SERVICES | SUPPORT | CONTACT US | SEARCH
Compaq C

Compaq C
Run-Time Library Reference Manual for OpenVMS Systems


Previous Contents Index


[no]raw

Raw mode only works with the Curses input routines [w]getch and [w]getstr . Raw mode is not supported with the Compaq C RTL emulation of UNIX I/O, Terminal I/O, or Standard I/O.

Format

#include <curses.h>

raw()

noraw()


Description

Raw mode reads are satisfied on one of two conditions: after a minimum number (5) of characters are input at the terminal or after waiting a fixed time (10 seconds) from receipt of any characters from the terminal.

Example


 
/* Example of standard and raw input in Curses package. */ 
 
#include <curses.h> 
 
main() 
{ 
    WINDOW *win1; 
    char vert = '.', 
         hor = '.', 
         str[80]; 
 
    /* Initialize standard screen, turn echo off.  */ 
 
    initscr(); 
    noecho(); 
 
    /* Define a user window.  */ 
 
    win1 = newwin(22, 78, 1, 1); 
    leaveok(win1, TRUE); 
    leaveok(stdscr, TRUE); 
 
    box(stdscr, vert, hor); 
 
    /* Reset the video, refresh(redraw) both windows. */ 
 
    mvwaddstr(win1, 2, 2, "Test line terminated input"); 
    wrefresh(win1); 
 
    /* Do some input and output it. */ 
    nocrmode(); 
    wgetstr(win1, str); 
 
    mvwaddstr(win1, 5, 5, str); 
    mvwaddstr(win1, 7, 7, "Type something to clear screen"); 
    wrefresh(win1); 
 
    /* Get another character then delete the window. */ 
 
    wgetch(win1); 
    wclear(win1); 
 
    mvwaddstr(win1, 2, 2, "Test raw input"); 
    wrefresh(win1); 
 
    /* Do some raw input 5 chars or timeout - and output it. */ 
    raw(); 
    getstr(str); 
    noraw(); 
    mvwaddstr(win1, 5, 5, str); 
    mvwaddstr(win1, 7, 7, "Raw input completed"); 
    wrefresh(win1); 
 
    endwin(); 
} 


read

Reads bytes from a file and places them in a buffer.

Format

#include <unistd.h>

ssize_t read (int file_desc, void *buffer, size_t nbytes); (ISO POSIX-1)

int read (int file_desc, void *buffer, int nbytes); (COMPATABILITY)


Arguments

file_desc

A file descriptor. The specified file descriptor must refer to a file currently opened for reading.

buffer

The address of contiguous storage in which the input data is placed.

nbytes

The maximum number of bytes involved in the read operation.

Description

This function returns the number of bytes read. The return value does not necessarily equal nbytes. For example, if the input is from a terminal, at most one line of characters is read.

Note

The read function does not span record boundaries in a record file and, therefore, reads at most one record. A separate read must be done for each record.

Return Values

n The number of bytes read.
--1 Indicates a read error, including physical input errors, illegal buffer addresses, protection violations, undefined file descriptors, and so forth.

Example


#include <file.h> 
#include <unistd.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <fcntl.h> 
 
main() 
{ 
    int fd, 
        i; 
    char buf[10]; 
    FILE *fp ;          /* Temporary STDIO file */ 
 
    /* Create a dummy data file  */ 
 
    if ((fp = fopen("test.txt", "w+")) == NULL) { 
        perror("open"); 
        exit(1); 
    } 
    fputs("XYZ\n",fp) ; 
    fclose(fp) ; 
 
    /* And now practice "read" */ 
 
    if ((fd = open("test.txt", O_RDWR, 0, "shr=upd")) <= 0) { 
        perror("open"); 
        exit(0); 
    } 
 
    /* Read 2 characters into buf.  */ 
 
    if ((i = read(fd, buf, 2)) < 0) { 
        perror("read"); 
        exit(0); 
    } 
 
    /* Print out what was read.  */ 
 
    if (i > 0) 
        printf("buf='%c%c'\n", buf[0], buf[1]); 
 
    close(fd); 
}                                                           


readdir

Finds entries in a directory.

Format

#include <dirent.h>

struct dirent *readdir (DIR *dir_pointer);


Arguments

dir_pointer

A pointer to the dir structure of an open directory.

Description

This function returns a pointer to a structure representing the directory entry at the current position in the directory stream specified by dir_pointer, and positions the directory stream at the next entry. It returns a NULL pointer upon reaching the end of the directory stream. The dirent structure defined in the <dirent.h> header file describes a directory entry.

The type dir defined in the <dirent.h> header file represents a directory stream. A directory stream is an ordered sequence of all the directory entries in a particular directory. Directory entries represent files. You can remove from or add files to a directory asynchronously to the operation of the readdir function.

The pointer returned by the readdir function points to data that you can overwrite by another call to readdir on the same directory stream. This data is not overwritten by another call to readdir on a different directory stream.

If a file is removed from or added to the directory after the most recent call to the opendir or rewinddir function, whether a subsequent call to the readdir function returns an entry for that file, is unspecified.

When it reaches the end of the directory, or when it detects an invalid seekdir operation, the readdir function returns the null value.

An attempt to seek to an invalid location causes the readdir function to return the null value the next time it is called. A previous telldir function call returns the position.

The readdir function responds with UNIX style names if the appropriate opendir call was passed a UNIX style name.

The UNIX style names are displayed as follows:

  1. The name is converted to lower case.
  2. Only a single version of each file is displayed.
  3. The version number is stripped off the file specification, together with the version number delimiter.
  4. The .dir file type is stripped off the directory files.

For example:


Directory DISK:[DIRECTORY] 
 
NETSCAPE.;2 
NETSCAPE.;1 
NETSCAPE.DIR;1 
NETSCAPE.RPT;2 
NETSCAPE.SAV;3 
NETSCAPE.SAV;2 
NETSCAPE.SAV;1 
 
Total of 7 files. 

After an opendir ("DISK:[DIRECTORY]") call - OpenVMS format:


NETSCAPE.;2 
NETSCAPE.;1 
NETSCAPE.DIR;1 
NETSCAPE.RPT;2 
NETSCAPE.SAV;3 
NETSCAPE.SAV;2 
NETSCAPE.SAV;1 

After an opendir ("disk/directory") call - UNIX format


netscape. 
netscape 
netscape.rpt 
netscape.sav 

See also opendir , rewinddir , seekdir , and telldir in this section.


Example

See the program example in the description of closedir .


Return Values

x A pointer to an object of type struct dirent .
NULL Indicates an error, returns a pointer. The global errno indicates the error. When the end of the directory is encountered, errno is not changed.

realloc

Changes the size of the area pointed to by the first argument to the number of bytes given by the second argument. These functions are AST-reentrant.

Format

#include <stdlib.h>

void *realloc (void *ptr, size_t size);

Function Variants This function also has variants named _realloc32 and _realloc64 for use with 32-bit and 64-bit pointer sizes, respectively. See Section 1.8 for more information on using pointer-size-specific functions.

Arguments

ptr

Points to an allocated area, or can be NULL.

size

The new size of the allocated area.

Description

If ptr is the NULL pointer, the behavior of the realloc function is identical to the malloc function.

The contents of the area are unchanged up to the lesser of the old and new sizes. The ANSI C Standard states that "If the new size is larger than the old size, the value of the newly allocated portion of memory is indeterminate." For compatibility with old implementations, Compaq C initializes the newly allocated memory to 0.

For efficiency, the previous actual allocation could have been larger than the requested size. If it was allocated with malloc , the value of the portion of memory between the previous requested allocation and the actual allocation is indeterminate. If it was allocated with calloc , that same memory was initialized to 0. If your application relies on realloc initializing memory to 0, then use calloc instead of malloc to perform the initial allocation.

See also free , cfree , calloc , and malloc in this section.


Return Values

x The address of the area, quadword-aligned. The address is returned because the area may have to be moved to a new address to reallocate enough space. If the area was moved, the space previously occupied is freed.
NULL Indicates that space cannot be reallocated (for example, if there is not enough room).

[w]refresh

Repaint the specified window on the terminal screen. The refresh function acts on the stdscr window.

Format

#include <curses.h>

int refresh();

int wrefresh (WINDOW *win);


Argument

win

A pointer to the window.

Description

The result of this process is that the portion of the window not occluded by subwindows or other windows appears on the terminal screen. To see the entire occluded window on the terminal screen, call the touchwin function instead of the refresh or wrefresh function.

See also touchwin in this section.


Return Values

OK Indicates success.
ERR Indicates an error.

remove

Deletes a file.

Format

#include <stdio.h>

int remove (const char *file_spec);


Argument

file_spec

A pointer to the string that is an OpenVMS or a UNIX style file specification. The file specification can include a wildcard in its version number. So, for example, files of the form filename.txt;* can be deleted.

Description

If you specify a directory in the file name and it is a search list that contains an error, Compaq C for OpenVMS Systems interprets it as a file error.

The remove and delete functions are functionally equivalent in the Compaq C RTL.

See also delete in this section.


Return Values

0 Indicates success.
nonzero value Indicates failure.

rename

Gives a new name to an existing file.

Format

#include <stdio.h>

int rename (const char *old_file_spec, const char *new_file_spec);


Arguments

old_file_spec

A pointer to a string that is the existing name of the file to be renamed.

new_file_spec

A pointer to a string that is to be the new name of the file.

Description

If you try to rename a file that is currently open, the behavior is undefined. You cannot rename a file from one physical device to another. Both the old and new file specifications must reside on the same device.

If the new_file_spec does not contain a file extension, the file extension of old_file_spec is used. To rename a file to have no file extension, new_file_spec must contain a period (.) For example, the following renames SYS$DISK:[]FILE.DAT to SYS$DISK:[]FILE1.DAT:


rename("file.dat", "file1"); 

Whereas the following renames SYS$DISK:[]FILE.DAT to SYS$DISK:[]FILE1:


rename(file.dat", "file1."); 

Note

Because the rename function does special processing of the file extension, the caller must be careful when specifying the name of the renamed file in a call to a C Run-Time Library function that accepts a filename argument. For example, after the following call to the rename function, the new file should be opened as fopen("bar.dat",...) :


rename("foo.dat", "bar"); 


Return Values

0 Indicates success.
nonzero value Indicates failure.

rewind

Sets the file to its beginning.

Format

#include <stdio.h>

void rewind (FILE *file_ptr); (ISO POSIX-1)

int rewind (FILE *file_ptr); (DEC C EXTENSION)


Argument

file_ptr

A file pointer.

Description

The rewind function is equivalent to fseek (file_ptr, 0, seek_set) . You can use the rewind function with either record or stream files.

A successful call to rewind clears the error indicator for the file.

The ANSI C standard defines rewind as not returning a value; therefore, the function prototype for rewind is declared with a return type of void . However, since a rewind can fail, and since previous versions of the Compaq C RTL have declared rewind to return an int , the code for rewind does return 0 on success and --1 on failure.

See also fseek in this section.


rewinddir

Resets the position of the specified directory stream to the beginning of a directory.

Format

#include <dirent.h>

void rewinddir (DIR *dir_pointer);


Arguments

dir_pointer

A pointer to the dir structure of an open directory.

Description

This function resets the position of the specified directory stream to the beginning of the directory. It also causes the directory stream to refer to the current state of the corresonding directory, the same as using the opendir function. If the dir_pointer argument does not refer to a directory stream, the effect is undefined.

The type dir , defined in the <dirent.h> header file, represents a directory stream. A directory stream is an ordered sequence of all the directory entries in a particular directory. Directory entries represent files.

See also opendir in this section.


rindex

Searches for character in string.

Format

#include <strings.h>

char *rindex (const char *s, int c);

Function Variants This function also has variants named _rindex32 and _rindex64 for use with 32-bit and 64-bit pointer sizes, respectively. See Section 1.8 for more information on using pointer-size-specific functions.

Arguments

s

The string to search.

c

The character to search for.

Description

This function is identical to the strchr function, and is provided for compatibility with some UNIX implementations.

rmdir

Removes a directory file.

Format

#include <unistd.h>

int rmdir (const char *path);


Arguments

path

A directory path name.

Description

This function removes a directory file whose name is specified in the path argument. The directory is removed only if it is empty.

Restriction

When using OpenVMS format names, the path argument must be in the form directory.dir.

Return Values

0 Indicates success.
--1 An error occurred; errno is set to indicate the error.

sbrk

Determines the lowest virtual address that is not used with the program.

Format

#include <unistd.h>

void *sbrk (long int incr);


Argument

incr

The number of bytes to add to the current break address.

Description

This function adds the number of bytes specified by its argument to the current break address and returns the old break address.

When a program is executed, the break address is set to the highest location defined by the program and data storage areas. Consequently, sbrk is needed only by programs that have growing data areas.

sbrk(0) returns the current break address.


Return Values

x The old break address.
( void *)(--1) Indicates that the program is requesting too much memory.

Restriction

Unlike other C library implementations, the Compaq C RTL memory allocation functions (such as malloc ) do not rely on brk or sbrk to manage the program heap space. Consequently, on OpenVMS systems, calling brk or sbrk can interfere with memory allocation routines. The brk and sbrk functions are provided only for compatibility purposes.

scanf

Performs formatted input from the standard input (stdin), interpreting it according to the format specification. See Chapter 2 for information on format specifiers.

Format

#include <stdio.h>

int scanf (const char *format_spec, ...);


Arguments

format_spec

Characters to be taken literally from the input or converted and placed in memory at the specified input sources. For a list of conversion characters, see Chapter 2.

...

Optional expressions that are pointers to objects whose resultant types correspond to conversion specifications given in the format specification.

If no conversion specifications are given, you can omit these input pointers. Otherwise, the function call must have at least as many input pointers as there are conversion specifications, and the conversion specifications must match the types of the input pointers.

Conversion specifications are matched to input sources in left-to-right order. Excess input pointers, if any, are ignored.


Return Values

x The number of successfully matched and assigned input items.
EOF Indicates that a read error occurred prior to any successful conversions.The function sets errno . For a list of errno values set by this function, see fscanf in this section.


Previous Next Contents Index
  

1.800.AT.COMPAQ

privacy and legal statement