[Home]
[Search]
[CTG]
[RTL]
[IDDE]
tabsize.h
Prototype
unsigned short tab_sizeget(void);
Description
This function obtains the current setting of the global tab size.
Return Value
Returns the current global tab size.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
tab_sizegetenv
tab_sizeputenv
tab_sizeset
tabsize.h
Prototype
unsigned short tab_sizegetenv(void);
Description
Gets the value of the TAB environment variable. If no TAB variable exists, it will return the value of the TABS environment variable. If neither environment variable exists it will return 0.
Return Value
The value of TAB or TABS, if they exist, otherwise 0.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
tab_sizeget
tab_sizeputenv
tab_sizeset
tabsize.h
Prototype
void tab_sizeputenv(unsigned short newtabsize);
Description
Defines the environment variable TAB with a value equal to the specified tab size. It will undefine the environment variable TABS if it is present.
Return Value
None
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
tab_sizeget
tab_sizegetenv
tab_sizeset
tabsize.h
Prototype
void tab_sizeset(unsigned short newtabsize);
Description
This function changes the global tab size.
Return Value
None
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
tab_sizegetenv
tab_sizeputenv
tab_sizeset
unmangle.h
Prototype
char *unmangle_ident(char *ident)
Description
The unmangle_ident function unmangles the C++ identifier in the ident argument. The function allocates enough memory for the unmangled identifier and returns a pointer to this memory. You should deallocate this memory when you no longer need it.
Return Value
A pointer to the unmangled identifier.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
locale.h
Prototype
struct lconv * localeconv(void);
Description
localeconv returns a pointer to a filled-in struct lconv which
contains information specific to the current country or locale.
struct lconv looks like this:
struct lconv
{
char *decimal_point;
char *thousands_sep;
char *int_curr_symbol;
char *currency_symbol;
char *mon_decimal_point;
char *mon_thousands_sep;
char *negative_sign;
char frac_digits;
char p_cs_precedes;
char p_sep_by_space;
char n_cs_precedes;
char n_sep_by_space;
char n_sign_posn;
char lc[6];
};
The fields are:
Return Value
A pointer to a struct lconv. The values contained within the structure should be regarded as read only.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
Example
See setlocale
locale.h
Prototype
char * setlocale(int category, const char * locale);
Description
setlocale changes locale-dependent behavior or checks on its current settings. category can be one of the following predefined constants. Digital Mars C++ supports the minimal ANSI C definition and therefore only the following constants have an effect.
The following locales are recognized:
It also recognizes Italy, Netherlands, Norway, Switzerland, UK, Japan, Korea, China.
Information about the current locale can be obtained by calling setlocale with a NULL second argument. This will return the current locale for the category selected. Having set the locale, a call to localeconv will obtain a pointer to a filled in struct lconv with the specific locale values. See localeconv for details.
Return Value
A pointer containing the currently selected locale for the category specified. A NULL is returned if the locale specified is not supported.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
Example
/* Example for setlocale */
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *countries[] =
{
"USA",
"ITALY",
"NORWAY",
NULL
};
void main ()
{
char *loc,
*currency;
int i;
struct lconv *lcptr;
int money = 100; /* Something to display */
/*
setlocale can be called with a NULL locale to
check on its current setting
*/
loc = setlocale (LC_ALL, NULL);
printf (" The default locale is the \"%s\"
locale\n", loc);
for (i = 0; countries[i]; i++)
{
loc = setlocale (LC_ALL, countries[i]);
lcptr = localeconv ();
currency = malloc
(strlen (lcptr-> currency_symbol) + 1);
strcpy (currency, lcptr-> currency_symbol);
if (loc)
printf (" Monetary figure for %s locale:
%s%d\n", loc, currency, money);
free(currency);
}
}
Output
The default locale is the "C" locale
Monetary figure for USA locale: $100
Monetary figure for Italy locale: L. 100
Monetary figure for Norway locale: kr100
stddef.h
Prototype
extern unsigned long *__threadid(void);
Description
__threadid is the ID of the currently executing thread, allowing a program to distinguish that thread from others executing the same piece of code.
See Also
new.h
Prototype
_PNH _set_new_handler(_PNH pNewHandler);
Description
The _set_new_handler function defines a handler to be called when the new operator is unable to allocate a requested amount of memory from the default heap. The _set_fnew_handler function establishes a new handler for the far heap; _set_nnew_handler establishes a new handler for the near heap.
The _set_new_handler function automatically maps to either the _set_fnew_handler or _set_nnew_handler, depending on the default data model.
For all of the _set_new_handler functions, the pNewHandler argument is a pointer to the function that you write to be called when new fails. This argument is of type _PNH, which is a pointer to a function that returns type int and takes an argument of type size_t. Use size_t to specify the amount of space to allocate.
The _set_new_handler functions provide a garbage collection scheme. The run-time system retries allocation each time your function returns a non-zero value and fails if your function returns 0.
In a multi-threaded environment, handlers are maintained separately for each process and thread. Each new process does not have installed handlers. Each new thread receives a copy of its parent thread's new handlers. Therefore, each process and thread must manage its own free-store error handling.
Synonym
Function: set_new_handler
Return Value
Returns a pointer to the previous new handler function. There is no error return.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
calloc Functions
free Functions
malloc Functions
realloc Functions
Example
/* Example of _set_new_handler */
#include <stdlib.h>
#include <stdio.h>
#include <new.h>
#define MEMSIZE 1024
#define ZONESIZE MEMSIZE * 4
/* This is the safety zone. If this is eaten
into, then memory is low */
char * zone = new char[ZONESIZE];
char * forprintf = new char[128];
/* This handler will free the safety zone when
there is an allocation error. It won't
bother if the alloction request is too
big for the zone. */
int zone_handler (size_t alocsize)
{
if (alocsize > ZONESIZE)
{
delete forprintf;
printf("\nThat's it, now you've used up
all the memory.\n");
return 0;
}
if (zone)
{
delete zone;
zone = NULL;
printf("\nWARNING: Memory is low,
they have taken the zone!\n");
return 1;
}
delete forprintf;
printf("\nThat's it, now you've used up
all the memory.\n"); return 0;
}
void main ()
{
char * waste;
unsigned long int total_wasted = 0;
_set_new_handler (zone_handler);
printf(" Wasting memory...\n");
do
{
printf("\rWasting %u", total_wasted);
waste = new char[MEMSIZE];
total_wasted += MEMSIZE;
} while (waste);
}
Output
Wasting memory...
Wasting 46080
WARNING: Memory is low, they have taken the zone!
Wasting 49152
That's it, now you've used up all the memory.
search.h
Prototype
void *_lfind(const void *key, const void *base, unsigned int *num, unsigned int width, int(__cdecl *compare) (const void *, const void *));
Description
The _lfind function performs a linear search for the value key in the array pointed to by base. The array has num elements; each element has a size of width bytes.
The compare argument is a pointer to a user-supplied routine that compares two array elements and returns a value specifying their relationship. A non-zero value indicates that the elements are different; 0 indicates that the elements are the same.
Synonym
Function: lfind
Return Value
A pointer to the first array element that matches key. If no match is found, NULL is returned.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
Example
/* Example of _lfind */
#include <stdio.h>
#include <search.h>
int compare (int *x, int *y)
{
return (* x -*y);
}
void main ()
{
int array[5] = {44, 69, 3, 17, 23};
size_t elems = 5;
int key = 69;
int *result;
result = (int *)_lfind (& key, &array, &elems,
sizeof (int),
(int(*) (const void *,
const void *)) compare);
if (result)
printf (" Key %d found in linear search\n",
key);
else
printf (" Key %d not found in linear
search\n", key);
}
Output
Key 69 found in linear search
search.h
Prototype
void *_lsearch(const void *key, const void *base, unsigned int *num, unsigned int width, int (__cdecl *compare)(const void *, const void *));
Description
The _lsearch functions performs a linear search for the value key in the array pointed to by base. The array has num elements; each element has a size of width bytes. If the key value is not found during the search, the lsearch function adds it to the end of the array, and *num is incremented by 1.
The compare argument is a pointer to a user-supplied routine that compares two array elements and returns a value specifying their relationship. A non-zero value indicates that the elements are different; 0 indicates that the elements are the same.
Synonym
Function: lsearch
Return Value
A pointer to the first array element that matches key. If no match is found, the function returns a pointer to the newly added item at the end of the array.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
Example
/* Example of _lsearch */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <search.h>
char *animals[10] =
{
"Horse",
"Dog",
"Cat",
"Goat",
"Peacock"
};
size_t elems = 5;
int compare (char ** x, char ** y)
{
return (strcmp(* x, *y));
}
int addelem (char *key)
{
size_t num = elems;
_lsearch (& key, animals, &num, sizeof(char *),
(int (*)(const void *,
const void *)) compare);
return (elems == num);
}
void main ()
{
char *key = "Donkey";
if (addelem (key))
printf (" Animal \"%s\" already exists in
array\n", key);
else
printf ("\"%s\" added to animals array\n", key);
}
Output
"Donkey" added to animals array
sys\stat.h
Prototype
int _fstat(int fd, struct stat *buf);
Description
The _fstat function gets information about an open file fd and stores it in the structure pointed to by buf. Some of the fields in the _stat structure are:
Field/Description
Function: fstat
Structure: stat
Modes: S_IFCHR, S_IFREG, S_IREAD, S_IWRITE
Return Value
A value of 0 if file information is successfully obtained. If the return value is -1, errno is set to EBADF indicating a bad file handle.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
_stat
findfirst
findnext
_isatty
Example
/* Example of _fstat */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <fcntl.h>
#include <sys\stat.h>
void main ()
{
char filen[_MAX_PATH];
char *date;
int res;
struct _stat fstat;
int fh;
printf (" Enter a filename: ");
gets (filen);
if ((fh = _open (filen, _O_RDONLY)) < 0)
{
perror (" Error opening file");
exit (EXIT_FAILURE);
}
if ((res = _fstat (fh, &fstat)) != 0)
{
perror (" Failure calling _fstat");
exit (EXIT_FAILURE);
}
date = asctime (localtime (& fstat. st_ctime));
printf ("\nDate: %s", date);
printf (" Mode: %d\n", fstat. st_mode);
printf (" Size: %ld\n", fstat. st_size);
}
Output
Enter a filename: _fstat. c
Date: Tue Jun 28 14: 11: 56 1994
Mode: -32330
Size: 760
sys/stat.h
sys/types.h
Prototype
int _stat(char *path, struct _stat *buf);
Description
The _stat function gets information about a file or directory specified by path and store the information in the structure that buf points to. The structure contains the following fields:
Use the following values for st_mode:
Synonym
Function: stat
Values: S_IFREG, S_IREAD, S_IWRITE, S_IFDIR, S_IEXEC
Return Value
stat returns 0 if the status information is retrieved. On error the function returns -1 and errno is set.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
Example
/* Example of _stat */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <sys\stat.h>
void main ()
{
char filen[_MAX_PATH];
char *date;
int res;
struct _stat fstat;
printf (" Enter a filename: ");
gets (filen);
if ((res = _stat (filen, &fstat)) != 0)
{
perror (" Failure calling _stat");
exit (EXIT_FAILURE);
}
date = asctime (localtime (& fstat. st_ctime));
printf ("\nDate: %s", date);
printf (" Mode: %d\n", fstat. st_mode);
printf (" Size: %ld\n", fstat. st_size);
}
Output
Enter a filename: _stat.c
Date: Thu Jun 23 09: 42: 04 1994
Mode: -32330
Size: 585
assert.h
Prototype
void assert(expression);
Description
This function is useful for adding internal consistency checks. When assert is executed it checks the expression argument and, if it is zero, displays the following message on the standard error device, after which the program aborts.
Assertion failure: 'expression' on line ?? in file '??? '
The assert function can be deactivated by defining the macro NDEBUG prior to the inclusion of assert.h header file. The effect is that all assertions become null statements.
Return Value
None
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
Example
/* Example of assert */
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
void main()
{
int value;
value = 3;
while (value)
{
assert (value > 1);
printf (" Passed assert (%d > 1)\n", value);
value--;
}
}
Output
Passed assert(3 > 1)
Passed assert(2 > 1)
Assertion failed: value > 1, file
c:\rtl\assert.c, line 13