Showing posts with label Functions. Show all posts
Showing posts with label Functions. Show all posts

string.h Definitions for memory and string functions

/* string.h

Definitions for memory and string functions.

Copyright (c) Borland International 1987,1988
All Rights Reserved.
*/
#if __STDC__
#define _Cdecl
#else
#define _Cdecl cdecl
#endif

#ifndef _SIZE_T
#define _SIZE_T
typedef unsigned size_t;
#endif

void *_Cdecl memccpy (void *dest, const void *src, int c, size_t n);
void *_Cdecl memchr (const void *s, int c, size_t n);
int _Cdecl memcmp (const void *s1, const void *s2, size_t n);
void *_Cdecl memcpy (void *dest, const void *src, size_t n);
int _Cdecl memicmp (const void *s1, const void *s2, size_t n);
void *_Cdecl memmove (void *dest, const void *src, size_t n);
void *_Cdecl memset (void *s, int c, size_t n);
void _Cdecl movedata(unsigned srcseg, unsigned srcoff, unsigned dstseg,
unsigned dstoff, size_t n);
char *_Cdecl stpcpy (char *dest, const char *src);
char *_Cdecl strcat (char *dest, const char *src);
char *_Cdecl strchr (const char *s, int c);
int _Cdecl strcmp (const char *s1, const char *s2);
char *_Cdecl strcpy (char *dest, const char *src);
size_t _Cdecl strcspn (const char *s1, const char *s2);
char *_Cdecl strdup (const char *s);
char *_Cdecl strerror(int errnum);
int _Cdecl stricmp (const char *s1, const char *s2);
size_t _Cdecl strlen (const char *s);
char *_Cdecl strlwr (char *s);
char *_Cdecl strncat (char *dest, const char *src, size_t maxlen);
int _Cdecl strncmp (const char *s1, const char *s2, size_t maxlen);
char *_Cdecl strncpy (char *dest, const char *src, size_t maxlen);
int _Cdecl strnicmp(const char *s1, const char *s2, size_t maxlen);
char *_Cdecl strnset (char *s, int ch, size_t n);
char *_Cdecl strpbrk (const char *s1, const char *s2);
char *_Cdecl strrchr (const char *s, int c);
char *_Cdecl strrev (char *s);
char *_Cdecl strset (char *s, int ch);
size_t _Cdecl strspn (const char *s1, const char *s2);
char *_Cdecl strstr (const char *s1, const char *s2);
char *_Cdecl strtok (char *s1, const char *s2);
char *_Cdecl strupr (char *s);

/* compatibility with other compilers */

#define strcmpi(s1,s2) stricmp(s1,s2)
#define strncmpi(s1,s2,n) strnicmp(s1,s2,n)

#if !__STDC__
char *_Cdecl _strerror (const char *s);
#endif


stdlib.h Definitions for common types, variables, and functions

/*      stdlib.h

        Definitions for common types, variables, and functions.

        Copyright (c) Borland International 1987,1988
        All Rights Reserved.
*/
#if __STDC__
#define _Cdecl
#else
#define _Cdecl  cdecl
#endif

#if     !defined(__STDLIB)
#define __STDLIB

#ifndef _SIZE_T
#define _SIZE_T
typedef unsigned size_t;
#endif

#ifndef _DIV_T
#define _DIV_T
typedef struct {
        int     quot;
        int     rem;
} div_t;
#endif

#ifndef _LDIV_T
#define _LDIV_T
typedef struct {
        long    quot;
        long    rem;
} ldiv_t;
#endif

#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1

/* Maximum value returned by "rand" function
*/
#define RAND_MAX 0x7FFF

typedef void _Cdecl (* atexit_t)(void);

void    _Cdecl abort  (void);
int     _Cdecl abs    (int x);
int     _Cdecl atexit (atexit_t func);
double  _Cdecl atof   (const char *s);
int     _Cdecl atoi   (const char *s);
long    _Cdecl atol   (const char *s);
void   *_Cdecl bsearch(const void *key, const void *base,
                       size_t nelem, size_t width,
                       int _Cdecl (*fcmp)(/* const void *, const void * */));
void   *_Cdecl calloc (size_t nitems, size_t size);
div_t   _Cdecl div    (int numer, int denom);
void    _Cdecl exit   (int status);
void    _Cdecl free   (void *block);
char   *_Cdecl getenv (const char *name);
long    _Cdecl labs   (long x);
ldiv_t  _Cdecl ldiv   (long numer, long denom);
void   *_Cdecl malloc (size_t size);
void    _Cdecl qsort  (void *base, size_t nelem, size_t width,
                       int _Cdecl (*fcmp)(/* const void *, const void * */));
int     _Cdecl rand   (void);
void   *_Cdecl realloc(void *block, size_t size);
void    _Cdecl srand  (unsigned seed);
double  _Cdecl strtod (const char *s, char **endptr);
long    _Cdecl strtol (const char *s, char **endptr, int radix);
unsigned long _Cdecl strtoul (const char *s, char **endptr, int radix);
int     _Cdecl system (const char *command);

#if !__STDC__

#ifndef NULL
#if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
#define NULL    0
#else
#define NULL    0L
#endif
#endif

/* Variables */
extern  int             _Cdecl _doserrno;
extern  char          **_Cdecl environ;
extern  int             _Cdecl errno;
extern  int             _Cdecl _fmode;
extern  unsigned char   _Cdecl _osmajor;
extern  unsigned char   _Cdecl _osminor;
extern  unsigned        _Cdecl _psp;
extern  char           *_Cdecl sys_errlist[];
extern  int             _Cdecl sys_nerr;
extern  unsigned int    _Cdecl _version;

int     _Cdecl __abs__(int x);          /* This is an in-line function */
#define abs(x)          __abs__(x)
#define atoi(s)         ((int) atol (s))

#define max(a,b)        (((a) > (b)) ? (a) : (b))
#define min(a,b)        (((a) < (b)) ? (a) : (b))

#define random(num)     (rand() % (num))
#define randomize()     srand((unsigned)time(NULL))

char   *_Cdecl ecvt     (double value, int ndig, int *dec, int *sign);
void    _Cdecl _exit    (int status);
char   *_Cdecl fcvt     (double value, int ndig, int *dec, int *sign);
char   *_Cdecl gcvt     (double value, int ndec, char *buf);
char   *_Cdecl itoa     (int value, char *string, int radix);
void   *_Cdecl lfind    (const void *key, const void *base,
                         size_t *num, size_t width,
                         int _Cdecl (*fcmp)(/* const void *, const void * */));

unsigned long _Cdecl _lrotl(unsigned long val, int count);
unsigned long _Cdecl _lrotr(unsigned long val, int count);

void   *_Cdecl lsearch  (const void *key, void *base,
                         size_t *num, size_t width,
                         int _Cdecl (*fcmp)(/* const void *, const void * */));
char   *_Cdecl ltoa     (long value, char *string, int radix);
int     _Cdecl putenv   (const char *name);

unsigned _Cdecl _rotl   (unsigned value, int count);
unsigned _Cdecl _rotr   (unsigned value, int count);

void    _Cdecl swab     (char *from, char *to, int nbytes);
char   *_Cdecl ultoa    (unsigned long value, char *string, int radix);
#endif

#endif


stat.h Definitions used for file status functions

/* stat.h

Definitions used for file status functions

Copyright (c) Borland International 1987,1988
All Rights Reserved.
*/
#if __STDC__
#define _Cdecl
#else
#define _Cdecl cdecl
#endif

#ifndef _STAT_H
#define _STAT_H 1

#define S_IFMT 0xF000 /* file type mask */
#define S_IFDIR 0x4000 /* directory */
#define S_IFIFO 0x1000 /* FIFO special */
#define S_IFCHR 0x2000 /* character special */
#define S_IFBLK 0x3000 /* block special */
#define S_IFREG 0x8000 /* or just 0x0000, regular */
#define S_IREAD 0x0100 /* owner may read */
#define S_IWRITE 0x0080 /* owner may write */
#define S_IEXEC 0x0040 /* owner may execute <directory search> */

struct stat
{
short st_dev;
short st_ino;
short st_mode;
short st_nlink;
int   st_uid;
int   st_gid;
short st_rdev;
long  st_size;
long  st_atime;
long  st_mtime;
long  st_ctime;
};

int  _Cdecl fstat (int handle, struct stat *statbuf);
int  _Cdecl stat  (char *path, struct stat *statbuf);

#endif /* _STAT_H */


alloc.h memory management functions and variables

/* alloc.h

memory management functions and variables.

Copyright (c) Borland International 1987,1988
All Rights Reserved.
*/
#if __STDC__
#define _Cdecl
#else
#define _Cdecl cdecl
#endif

#ifndef _STDDEF
#define _STDDEF
#ifndef _PTRDIFF_T
#define _PTRDIFF_T
#if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
typedef long ptrdiff_t;
#else
typedef int ptrdiff_t;
#endif
#endif
#ifndef _SIZE_T
#define _SIZE_T
typedef unsigned size_t;
#endif
#endif

#ifndef NULL
#if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
#define NULL 0
#else
#define NULL 0L
#endif
#endif

int _Cdecl brk (void *addr);
void *_Cdecl calloc (size_t nitems, size_t size);

#if defined(__COMPACT__) || defined(__LARGE__) || defined(__HUGE__)
unsigned long _Cdecl coreleft (void);
#else
unsigned _Cdecl coreleft (void);
#endif

void _Cdecl free (void *block);
void *_Cdecl malloc (size_t size);
void *_Cdecl realloc (void *block, size_t size);
void *_Cdecl sbrk (int incr);

#if !__STDC__
void far  * _Cdecl farcalloc (unsigned long nunits, unsigned long unitsz);
unsigned long _Cdecl farcoreleft(void);
void _Cdecl      farfree (void far *block);
void far  *_Cdecl farmalloc (unsigned long nbytes);
void far  *_Cdecl farrealloc (void far *oldblock, unsigned long nbytes);
#endif

sizeof() in C++

sizeof()

This operator accepts one parameter, which can be either a type or a variable itself and returns the size in bytes of
that type or object:
a = sizeof (char);
This will assign the value 1 to a because char is a one-byte long type.
The value returned by sizeof is a constant, so it is always determined before program execution.

Structure of a program in C++ Learn

Data+Structure+C+++Programs

C++ Programming Language

Probably the best way to start learning a programming language is by writing a program. Therefore, here is our
first program:
// my first program in C++
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
return 0;
}
Hello World!
The first panel shows the source code for our first program. The second one shows the result of the program once
compiled and executed. The way to edit and compile a program depends on the compiler you are using. Depending
on whether it has a Development Interface or not and on its version. Consult the compilers section and the manual
or help included with your compiler if you have doubts on how to compile a C++ console program.

io.h Definitions for low level I/O functions.

Copyright (c) Borland International 1987,1988
All Rights Reserved.
*/
#if __STDC__
#define _Cdecl
#else
#define _Cdecl cdecl
#endif

#ifndef _IO_H
#define _IO_H 1

#define HANDLE_MAX 20U

extern unsigned int _Cdecl _openfd[];

struct ftime {
unsigned ft_tsec : 5; /* Two second interval */
unsigned ft_min : 6; /* Minutes */
unsigned ft_hour : 5; /* Hours */
unsigned ft_day : 5; /* Days */
unsigned ft_month : 4; /* Months */
unsigned ft_year : 7; /* Year */
};

#define SEEK_CUR 1
#define SEEK_END 2
#define SEEK_SET 0

int  _Cdecl access (const char *path, int amode);
int  _Cdecl _chmod (const char *path, int func, ... /* int attr */);
int  _Cdecl chmod (const char *path, int amode);
int  _Cdecl chsize (int handle, long size);
int  _Cdecl _close (int handle);
int  _Cdecl close (int handle);
int  _Cdecl _creat (const char *path, int attribute);
int  _Cdecl creat (const char *path, int amode);
int  _Cdecl creatnew (const char *path, int mode); /* DOS 3.0 or later */
int  _Cdecl creattemp (char *path, int amode); /* DOS 3.0 or later */
int  _Cdecl dup (int handle);
int  _Cdecl dup2 (int oldhandle, int newhandle);
int  _Cdecl eof (int handle);
long _Cdecl filelength (int handle);
int  _Cdecl getftime (int handle, struct ftime *ftimep);
int  _Cdecl ioctl (int handle, int func, ...);
/* optional 3rd and 4th args are: void * argdx, int argcx */
int  _Cdecl isatty (int handle);
int  _Cdecl lock (int handle, long offset, long length);
long _Cdecl lseek (int handle, long offset, int fromwhere);
int  _Cdecl _open (const char *path, int oflags);
int  _Cdecl open (const char *path, int access,... /*unsigned mode*/);
int  _Cdecl _read (int handle, void *buf, unsigned len);
int  _Cdecl read (int handle, void *buf, unsigned len);
int  _Cdecl setftime (int handle, struct ftime *ftimep);
int  _Cdecl setmode (int handle, int amode);
long _Cdecl tell (int handle);
unsigned _Cdecl umask (unsigned cmask);
int  _Cdecl unlink (const char *path);
int  _Cdecl unlock (int handle, long offset, long length);
int  _Cdecl _write (int handle, void *buf, unsigned len);
int  _Cdecl write (int handle, void *buf, unsigned len);

/* macros for compatibility with earlier versions & other compilers. */
#define sopen(path,access,shflag,mode) open (path, (access)|(shflag), mode)

#endif /* _IO_H */

dos.h Defines structs, unions, macros, and functions for dealing with MSDOS and the Intel iAPX86 microprocessor family.

Copyright (c) Borland International 1987,1988
All Rights Reserved.
*/
#if __STDC__
#define _Cdecl
#else
#define _Cdecl cdecl
#endif

#if     !defined(__DOS_DEF_)
#define __DOS_DEF_

/* Variables */
extern int _Cdecl _8087;
extern int _Cdecl _argc;
extern char      **_Cdecl _argv;
extern char      **_Cdecl  environ;
extern int _Cdecl _doserrno;
extern unsigned _Cdecl _heaplen;
extern unsigned char _Cdecl _osmajor;
extern unsigned char _Cdecl _osminor;
extern unsigned _Cdecl _psp;
extern unsigned _Cdecl _stklen;
extern unsigned _Cdecl _version;

#define FA_RDONLY 0x01 /* Read only attribute */
#define FA_HIDDEN 0x02 /* Hidden file */
#define FA_SYSTEM 0x04 /* System file */
#define FA_LABEL 0x08 /* Volume label */
#define FA_DIREC 0x10 /* Directory */
#define FA_ARCH 0x20 /* Archive */

#define NFDS 20 /* Maximum number of fds */

struct fcb {
char fcb_drive; /* 0 = default, 1 = A, 2 = B */
char fcb_name[8]; /* File name */
char fcb_ext[3]; /* File extension */
short fcb_curblk; /* Current block number */
short fcb_recsize; /* Logical record size in bytes */
long fcb_filsize; /* File size in bytes */
short fcb_date; /* Date file was last written */
char fcb_resv[10]; /* Reserved for DOS */
char fcb_currec; /* Current record in block */
long fcb_random; /* Random record number */
};

struct xfcb {
char xfcb_flag; /* Contains 0xff to indicate xfcb */
char xfcb_resv[5]; /* Reserved for DOS */
char xfcb_attr; /* Search attribute */
struct fcb xfcb_fcb; /* The standard fcb */
};

struct country {
int co_date;
char co_curr[5];
char co_thsep[2];
char co_desep[2];
char co_dtsep[2];
char co_tmsep[2];
char co_currstyle;
char co_digits;
char co_time;
long co_case;
char co_dasep[2];
char co_fill[10];
};

struct DOSERROR {
int exterror;
char class;
char action;
char locus;
};

struct dfree {
unsigned df_avail;
unsigned df_total;
unsigned df_bsec;
unsigned df_sclus;
};

struct fatinfo {
char fi_sclus;
char fi_fatid;
int fi_nclus;
int fi_bysec;
};

struct devhdr {
long dh_next; /* Next device pointer */
short dh_attr; /* Attributes */
unsigned short dh_strat; /* Driver strategy routine */
unsigned short dh_inter; /* Driver interrupt routine */
char dh_name[8]; /* Device name */
};

struct time {
unsigned char ti_min; /* Minutes */
unsigned char ti_hour; /* Hours */
unsigned char ti_hund; /* Hundredths of seconds */
unsigned char ti_sec; /* Seconds */
};

struct date {
int da_year; /* Year - 1980 */
char da_day; /* Day of the month */
char da_mon; /* Month (1 = Jan) */
};

struct WORDREGS {
unsigned int ax, bx, cx, dx, si, di, cflag, flags;
};

struct BYTEREGS {
unsigned char al, ah, bl, bh, cl, ch, dl, dh;
};

union REGS {
struct WORDREGS x;
struct BYTEREGS h;
};

struct SREGS {
unsigned int es;
unsigned int cs;
unsigned int ss;
unsigned int ds;
};

struct REGPACK {
unsigned r_ax, r_bx, r_cx, r_dx;
unsigned r_bp, r_si, r_di, r_ds, r_es, r_flags;
};

#define FP_OFF(fp) ((unsigned)(fp))
#define FP_SEG(fp) ((unsigned)((unsigned long)(fp) >> 16))


typedef struct {
char drive; /* do not change */
char pattern [13]; /*  these fields, */
char reserved [7]; /*   Microsoft reserved */
char attrib;
short time;
short date;
long size;
char nameZ [13]; /* result of the search, asciiz */
} dosSearchInfo; /* used with DOS functions 4E, 4F */


int _Cdecl absread (int drive, int nsects, int lsect, void *buffer);
int _Cdecl abswrite(int drive, int nsects, int lsect, void *buffer);
int _Cdecl allocmem(unsigned size, unsigned *segp);
int _Cdecl bdos (int dosfun, unsigned dosdx, unsigned dosal);
int _Cdecl bdosptr (int dosfun, void *argument, unsigned dosal);
struct country *_Cdecl country (int xcode, struct country *cp);
void _Cdecl ctrlbrk (int _Cdecl (*handler)(void));
void _Cdecl delay (unsigned milliseconds);
void _Cdecl disable (void);
int _Cdecl dosexterr (struct DOSERROR *eblkp);
long _Cdecl dostounix (struct date *d, struct time *t);
void          __emit__();
void _Cdecl enable (void);
int _Cdecl freemem (unsigned segx);
int _Cdecl getcbrk (void);
void _Cdecl getdate (struct date *datep);
void _Cdecl getdfree(unsigned char drive, struct dfree *dtable);
void _Cdecl getfat (unsigned char drive, struct fatinfo *dtable);
void _Cdecl getfatd (struct fatinfo *dtable);
unsigned _Cdecl getpsp (void);
int _Cdecl getswitchar (void);
void _Cdecl gettime (struct time *timep);
void interrupt (* _Cdecl getvect(int interruptno)) ();
int _Cdecl getverify (void);
void _Cdecl harderr (int _Cdecl (*handler)());
void _Cdecl hardresume (int axret);
void _Cdecl hardretn(int retn);
int _Cdecl inport (int portid);
unsigned char _Cdecl inportb(int portid);
int _Cdecl int86 (int intno, union REGS *inregs, union REGS *outregs);
int _Cdecl int86x (int intno, union REGS *inregs, union REGS *outregs,
struct SREGS *segregs);
int _Cdecl intdos (union REGS *inregs, union REGS *outregs);
int _Cdecl intdosx (union REGS *inregs, union REGS *outregs,
struct SREGS *segregs);
void _Cdecl intr (int intno, struct REGPACK *preg);
void _Cdecl keep (unsigned char status, unsigned size);
void _Cdecl nosound (void);
void _Cdecl outport (int portid, int value);
void _Cdecl outportb(int portid, unsigned char value);
char *_Cdecl parsfnm (const char *cmdline, struct fcb *fcb, int opt);
int _Cdecl peek (unsigned segment, unsigned offset);
char _Cdecl peekb (unsigned segment, unsigned offset);
void _Cdecl poke (unsigned segment, unsigned offset, int value);
void _Cdecl pokeb (unsigned segment, unsigned offset, char value);
int _Cdecl randbrd (struct fcb *fcb, int rcnt);
int _Cdecl randbwr (struct fcb *fcb, int rcnt);
void _Cdecl segread (struct SREGS *segp);
int _Cdecl setblock(unsigned segx, unsigned newsize);
int _Cdecl setcbrk (int cbrkvalue);
void _Cdecl setdate (struct date *datep);
void _Cdecl setswitchar (char ch);
void _Cdecl settime (struct time *timep);
void _Cdecl setvect (int interruptno, void interrupt (*isr) ());
void _Cdecl setverify (int value);
void _Cdecl sleep (unsigned seconds);
void _Cdecl sound (unsigned frequency);
void _Cdecl unixtodos (long time, struct date *d, struct time *t);
int _Cdecl unlink (const char *path);

/* These are in-line functions.  These prototypes just clean up
  some syntax checks and code generation.
*/

void _Cdecl __cli__ (void);
void _Cdecl __sti__ (void);
unsigned char _Cdecl __inportb__(int portid);
void _Cdecl __outportb__ (int portid, unsigned char value);
void _Cdecl __int__ (int interruptnum);

#define disable() __cli__() /* Clear interrupt flag */
#define enable() __sti__() /* Set interrupt flag */
#define inportb(portid) __inportb__(portid) /* Byte IN instruction */
#define outportb(portid, v) __outportb__(portid,v)/* Byte OUT instruction */
#define geninterrupt(i) __int__(i) /* Interrupt instruction */

/* some other compilers use inp, outp for inportb, outportb */
#define inp(portid) inportb(portid)
#define outp(portid,v) outportb(portid,v)

#if !__STDC__
char far *cdecl getdta(void);
void  cdecl setdta(char far *dta);

#define MK_FP(seg,ofs) ((void far *) \
  (((unsigned long)(seg) << 16) | (unsigned)(ofs)))

#define poke(a,b,c) (*((int  far*)MK_FP((a),(b))) = (int)(c))
#define pokeb(a,b,c) (*((char far*)MK_FP((a),(b))) = (char)(c))
#define peek(a,b) (*((int  far*)MK_FP((a),(b))))
#define peekb(a,b) (*((char far*)MK_FP((a),(b))))
#endif

#endif

dir.h Defines structures, macros, and functions for dealing with directories and pathnames.

Copyright (c) Borland International 1987,1988
All Rights Reserved.
*/
#if __STDC__
#define _Cdecl
#else
#define _Cdecl cdecl
#endif

#if     !defined(__DIR_DEF_)
#define __DIR_DEF_

struct ffblk {
char ff_reserved[21];
char ff_attrib;
unsigned ff_ftime;
unsigned ff_fdate;
long ff_fsize;
char ff_name[13];
};

#define WILDCARDS 0x01
#define EXTENSION 0x02
#define FILENAME  0x04
#define DIRECTORY 0x08
#define DRIVE  0x10

#define MAXPATH   80
#define MAXDRIVE  3
#define MAXDIR  66
#define MAXFILE   9
#define MAXEXT  5

int _Cdecl chdir (const char *path);
int _Cdecl findfirst (const char *path, struct ffblk *ffblk,
int attrib);
int _Cdecl findnext (struct ffblk *ffblk);
void _Cdecl fnmerge (char *path,const char *drive,const char *dir,
const char *name, const char *ext);
int _Cdecl fnsplit (const char *path, char *drive, char *dir,
char *name, char *ext);
int _Cdecl getcurdir (int drive, char *directory);
char *_Cdecl getcwd (char *buf, int buflen);
int _Cdecl getdisk (void);
int _Cdecl mkdir (const char *path);
char *_Cdecl mktemp (char *template);
int _Cdecl rmdir (const char *path);
char *_Cdecl searchpath (const char *file);
int _Cdecl setdisk (int drive);

#endif