Deep understanding of C language-08 library functions

Source: Internet
Author: User

To do their best, you must first sharpen your tools.

To use any language, you must first master the database. Only in this way can you stand on the shoulders of giants and see farther.

The C language library is mainly libc, and the most used in the embedded development environment is uclibc.

Introduction to library functions, recommended book: Quick query efficiency manual for brain power C language functions

The following two steps may be helpful to the development of library functions.
1> take a quick look at the book and organize an Excel document with the following content: function name, parameter description, header file, and sample code.
2> Create a SouceInsight project. If one is used in actual development, add a test code for the function.

This provides an advantage for quick search in a non-network development environment.
In addition, in a specific environment, it is necessary to test the sub-database functions to see if there are implementation differences.

The following lists some common functions:

# Include Character Type judgment

Int isalpha (int ch );
Int isdigit (int ch );
Int isalnum (int ch );
Int islower (int ch );
Int isupper (int ch );
Int isspace (int ch );


# Include String processing
Char * strcpy (char * dst, char * src );
Char * strncpy (char * dst, char * src, int n );
Char * strcat (char * dst, char * src );
Char * strncat (char * dst, char * src, int n );
Char * strchr (const char * src, char ch );
Char * strrchr (const char * src, char ch );
Char * strstr (const char * s1, char * s2 );
Char * strcmp (const char * s1, char * s2 );
Char * stricmp (const char * s1, char * s2 );
Char * strnicmp (const char * s1, char * s2, int maxlen );
Int strlen (char * s );
Char * strlwr (char * s );
Char * strupr (char * s );

# Include Console-related
Int kbhit (void );
Int getch (void );
Int getchar (void );
Int putch (int ch );
Int putchar (int ch );

# Include
Int printf (char * fmt [, args]);
Int vprintf (char * fmt, va_list param );
Int sprintf (char * buf, char * fmt [, args]);
Int vsprintf (char * fmt, va_list param );

# Include
Int ioctl (int fd, int request, void *);

# Include
Typdef void (* sig_t) (int );
Sig_t signal (int signum, sig_t handler );
Int raise (int signum );

# Include
Int system (const char * cmd );

# Include
# Include
# Include
# Include
Int rename (char * oldname, char * newname );
Int open (char * path, int access [, int permiss]);
Int read (int fd, void * buf, int nByte );
Int write (int fd, void * buf, int nByte );
Int eof (int fd );
Int lseek (int fd, long offset, int origin );
Long tell (int fd );
Int isatty (int fd );

# Include
Int lock (int fd, long offset, int len );
Int unlock (int fd, long offset, int len );

Int close (int fd );

# Include
FILE * fopen (char * path, char * mode );
Size_t fread (void * buf, size_t size, size_t count, FILE * stream );
Size_t fwrite (void * buf, size_t size, size_t count, FILE * stream );
Int feof (FILE * stream );
Int fseek (FILE * stream, long offset, int origin );
Long ftell (FILE * stream );
Int ferror (FILE * stream );
Int fclose (FILE * stream );

/* Buffer */
Void setbuf (FILE * stream, char * buf );
Int setvbuf (FILE * stream, char * buf, int type, unsigned size );
Int fflush (FILE * stream );

/* Format */
Int fprint (FILE * stream, char * format [, args]);
Int vfprint (FILE * stream, char * format, va_list param );

/* File permission management */
Int chmod (char * path, int mode );
Int access (char * path, int mode );
Int getftime (int fd, struct ftime * pftime );
Int setftime (int fd, struct ftime * pftime );
Long filelength (int fd );
Int setmode (int fd, unsigned mode );

# Include
Int abs (int I );
Double sin (double x );
Double cos (double x );
Double exp (double x );
Double log (double x );
Float pow (float x, float y );
Double sqrt (double x );
Double ceil (double x );
Double floor (double x );
Void srand (unsigned seed );
Int rand (void );

/* Time Function */
# Include
Void getdate (struct date * pDate );
Void setdate (struct date * pDate ):
Void gettime (struct time * pTime );
Void settime (struct time * pTime );
Time_t time (time_t * timer );
Double difftime (time_t t1, time_t t2 );

/* Type conversion */
# Include
Char * ltoa (long value, char * str, int radix );
Char * itoa (int value, char * str, int radix );
Double atof (char * str );
Int atoi (char * str );
Long atol (char * str );
Int tolower (int ch );
Int toupper (int ch );

/* Handle errors */
# Include
Void assert (int exp );
Void perror (char * str );
Char * strerror (int errno );

/* Process control */
# Include
Void abort (void );
Int exit (int ret );
Int _ exit (int ret );
Int atexit (void (* exitfun) (void ));

# Include
Int execl (char * pathname, char * arg0, char * arg1 ,..., Char * argn, NULL );
Int execle (char * pathname, char * arg0, char * arg1 ,..., Char * argn, NULL, char * envp []);
Int execlp (char * pathname, char * arg0, char * arg1 ,..., NULL );
Int execlpe (char * pathname, char * arg0, char * arg1 ,..., NULL, char * envp []);
Int execv (char * pathname, char * argv []);
Int execve (char * pathname, char * argv [], char * envp []);
Int execvp (char * pathname, char * argv []);
Int execvpe (char * pathname, char * argv [], char * envp []);

Int spawnl (int mode, char * pathname, char * arg0, char * arg1 ,..., Char * argn, NULL );
Int spawnle (int mode, char * pathname, char * arg0, char * arg1 ,..., Char * argn, NULL, char * envp []);
Int spawnlp (int mode, char * pathname, char * arg0, char * arg1 ,..., Char * argn, NULL );
Int spawnlpe (int mode, char * pathname, char * arg0, char * arg1 ,..., Char * argn, NULL, char * envp []);
Int spawnv (int mode, char * pathname, char * argv []);
Int spawnve (int mode, char * pathname, char * argv [], char * envp []);
Int spawnvp (int mode, char * pathname, char * argv []);
Int spawnvpe (int mode, char * pathname, char * argv [], char * envp []);

/* Memory related */
Void * calloc (unsigned n, unsigned size );
Void * malloc (unsigned int size );
Void free (void * ptr );

For unknown functions, we strongly recommend that you read AUPE (Advanced Programming in Unix environment ).
In terms of the help value of my work, this book ranks first in my mind.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.