DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

sdget(S)


sdget, sdfree -- attaches and detaches a shared data segment.

Syntax

cc . . . -lx

#include  <sys/sd.h>

char *sdget(path, flags, [size, mode]) char *path; int flags, mode; long size;

int sdfree(addr); char *addr;

Description

sdget attaches a shared data segment to the data space of the current process. The actions performed are controlled by the value of flags. flags values are constructed by OR-ing flags from the following list:


SD_RDONLY
Attach the segment for reading only.

SD_WRITE
Attach the segment for both reading and writing.

SD_CREAT
If the segment named by path exists and is not in use (active), this flag has the same effect as creating a segment from scratch. Otherwise, the segment is created according to the values of size and mode. Read and write access to the segment is granted to other processes based on the permissions passed in mode, and functions the same as those for regular files. Execute permission is meaningless. The segment is initialized to contain all zeroes.

SD_UNLOCK
If the segment is created because of this call, the segment is made so that more than one process can be between sdenter and sdleave calls.

sdfree detaches the current process from the shared data segment that is attached at the specified address. If the current process has done sdenter but not an sdleave for the specified segment, sdleave is done before detaching.

When no process remains attached to the segment, the contents of that segment disappear, and no process can attach to the segment without creating it by using the SD_CREAT flag in sdget. errno is set to EEXIST if a process tries to create a shared data segment that exists and is in use. errno is set to ENOTNAM if a process attempts an sdget on a file that exists but is not a shared data type.

Notes

Use of the SD_UNLOCK flag on systems without hardware support for shared data may cause severe performance degradation.

For 286 programs, it is strongly recommended that sdget and other shared data functions be reserved for large model programs only. Small or middle model programs that attempt to use shared data may run out of available memory. Also, due to the 286 hardware, it is not possible to enforce the read-only aspect of small model shared data. However, read-only segments are honored in large model programs.

The 386 provides a 32 bit address space, even in small model. As a result, shared data may be conveniently used without regard to the restrictions that apply to 286 programs.

sdget automatically increments the process's original break value to the memory location immediately after the shared data segment. This affects subsequent sbrk or brk calls which attempt to restore the original break value. In particular, attempts to restore the break value to its value before the sdget call causes an error.

This feature is a XENIX specific enhancement and may not be present in all UNIX implementations. This routine must be linked using the linker option -lx.

The size variable in sdget has changed from unsigned to long between UNIX Version 3.0 and UNIX System V. Although this requires that source code be modified to use a long size parameter when compiling with the libraries, an unsigned size parameter is still correctly interpreted by the kernel when passed by binaries compiled with the Version 3.0 libraries.

Return value

On successful completion, the address at which the segment was attached is returned. Otherwise, -1 is returned, and errno is set to indicate the error.

The mode parameter must be included on the first call of the sdget function.

Diagnostics

sdget() will fail if one or more of the following are true:

[EEXIST]
A process tried to create a shared data segment that exists and is in use.

[EINVAL]
A process attempted an sdget() on a shared data segment to which it is already attached.

[ELOOP]
The file name specified is resolvable due to a lengthy symbolic link.

[ENAMETOOLONG]
The file name specified is too long.

[ENOTDIR]
The path specified contains a non-directory component.

[ENOTNAM]
A process attempted an sdget() on a file that exists but is not a shared data type.

See also

sbrk(S), sdenter(S), sdgetv(S)

Standards conformance

sdget and sdfree are not part of any currently supported standard; they are an extension of AT&T System V provided by the Santa Cruz Operation.
© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003