openharmony 鸿蒙 kernel-mini-appx-lib

2022-08-09 浏览 (1041)

Standard Libraries

CMSIS

Basic Concepts

The Cortex Microcontroller Software Interface Standard (CMSIS) is a vendor-independent hardware abstraction layer for microcontrollers based on Arm Cortex processors. Of the CMSIS components, the Real Time Operating System (RTOS) defines a set of universal and standardized APIs to reduce the dependency of application developers on specific RTOS and facilitate software porting and reuse. The CMSIS provides CMSIS-RTOS v1 and CMSIS-RTOS v2. The OpenHarmony LiteOS-M supports only the implementation of CMSIS-RTOS v2.

Development Guidelines

Available APIs

The following tables describe CMSIS-RTOS v2 APIs. For more details about the APIs, see the API reference.

Table 1 APIs for obtaining kernel information and controlling the kernel

APIDescription
osKernelGetInfoObtains RTOS kernel information.
osKernelGetStateObtains the current RTOS kernel status.
osKernelGetSysTimerCountObtains the RTOS kernel system timer count.
osKernelGetSysTimerFreqObtains the RTOS kernel system timer frequency.
osKernelInitializeInitializes the RTOS kernel.
osKernelLockLocks the RTOS kernel scheduler.
osKernelUnlockUnlocks the RTOS kernel scheduler.
osKernelRestoreLockRestores the RTOS kernel scheduler to the locked state.
osKernelResumeRestores the RTOS kernel scheduler (not implemented yet).
osKernelStartStarts the RTOS kernel scheduler.
osKernelSuspendSuspends the RTOS kernel scheduler (not implemented yet).
osKernelGetTickCountObtains the RTOS kernel tick count.
osKernelGetTickFreqObtains the RTOS kernel tick frequency.

Table 2 APIs for thread management

APIDescription
osThreadDetachDetaches a thread to reclaim the thread storage when the thread terminates (not implemented yet).
osThreadEnumerateEnumerates active threads (not implemented yet).
osThreadExitTerminates a running thread.
osThreadGetCountObtains the number of active threads.
osThreadGetIdObtains the ID of the running thread.
osThreadGetNameObtains the thread name.
osThreadGetPriorityObtains the current thread priority.
osThreadGetStackSizeObtains the thread stack size.
osThreadGetStackSpaceObtains the available stack space for a thread based on the stack waterline record during execution.
osThreadGetStateObtains the current thread status.
osThreadJoinWaits for the specified thread to terminate (not implemented yet).
osThreadNewCreates a thread and adds it to active threads.
osThreadResumeResumes the execution of a thread.
osThreadSetPriorityChanges the priority of a thread.
osThreadSuspendSuspends a thread.
osThreadTerminateTerminates a thread.
osThreadYieldPasses control to the next thread in the ready state.

Table 3 APIs for thread flags

APIDescription
osThreadFlagsSetSets flags for a thread (not implemented yet).
osThreadFlagsClearClears the specified flags for the running thread (not implemented yet).
osThreadFlagsGetObtains the current flags of the running thread (not implemented yet).
osThreadFlagsWaitWaits for one or more thread flags of the running thread to signal (not implemented yet).

Table 4 APIs for event flags

APIDescription
osEventFlagsGetNameObtains the event flag names (not implemented yet).
osEventFlagsNewCreates and initializes event flags.
osEventFlagsDeleteDeletes event flags.
osEventFlagsSetSets event flags.
osEventFlagsClearClears event flags.
osEventFlagsGetObtains the current event flags.
osEventFlagsWaitWaits for one or more event flags to be signaled.

Table 5 General wait functions

APIDescription
osDelayWaits for timeout (time delay).
osDelayUntilWaits until the specified time.

Table 6 APIs for timer management

APIDescription
osTimerDeleteDeletes a timer.
osTimerGetNameObtains the timer name (not implemented yet).
osTimerIsRunningChecks whether a timer is running.
osTimerNewCreates and initializes a timer.
osTimerStartStarts or restarts a timer.
osTimerStopStops a timer.

Table 7 APIs for mutex management

APIDescription
osMutexAcquireAcquires a mutex or times out (if locked).
osMutexDeleteDeletes a mutex.
osMutexGetNameObtains the mutex name (not implemented yet).
osMutexGetOwnerObtains the thread that acquires the mutex.
osMutexNewCreates and initializes a mutex.
osMutexReleaseReleases the mutex obtained using osMutexAcquire.

Table 8 APIs for semaphore management

APIDescription
osSemaphoreAcquireObtains the semaphore token or times out if no token is available.
osSemaphoreDeleteDeletes a semaphore.
osSemaphoreGetCountObtains the token count of the current semaphore.
osSemaphoreGetNameObtains the name of a semaphore (not implemented yet).
osSemaphoreNewCreates and initializes a semaphore.
osSemaphoreReleaseReleases semaphore tokens till the initial maximum count.

Table 9 APIs for memory pool management

APIDescription
osMemoryPoolAllocAllocates a memory block from the memory pool.
osMemoryPoolDeleteDeletes a memory pool object.
osMemoryPoolFreeReleases the allocated memory block to the memory pool.
osMemoryPoolGetBlockSizeObtains the memory block size in the memory pool.
osMemoryPoolGetCapacityObtains the maximum number of memory blocks in the memory pool.
osMemoryPoolGetCountObtains the number of used memory blocks in the memory pool.
osMemoryPoolGetNameObtains the memory pool name.
osMemoryPoolGetSpaceObtains the number of available memory blocks in the memory pool.
osMemoryPoolNewCreates and initializes a memory pool.

Table 10 APIs for message queues

APIDescription
osMessageQueueDeleteDeletes a message queue.
osMessageQueueGetObtain a message from the queue or times out if the queue is empty.
osMessageQueueGetCapacityObtains the maximum number of messages in the message queue.
osMessageQueueGetCountObtains the number of queued messages in the message queue.
osMessageQueueGetMsgSizeObtains the maximum message size in the memory pool.
osMessageQueueGetNameObtains the message queue name (not implemented yet).
osMessageQueueGetSpaceObtains the number of slots available for messages in the message queue.
osMessageQueueNewCreates and initializes a message queue.
osMessageQueuePutPuts the message into the queue or times out if the queue is full.
osMessageQueueResetResets the message queue to the initial empty state (not implemented yet).

How to Develop

The CMSIS-RTOS v2 component can be provided as a library (shown in the figure) or source code. By adding the CMSIS-RTOS v2 component (typically configuration files), you can implement RTOS capabilities on CMSIS-based applications. You only need to include the cmsis_os2.h header file. RTOS APIs can then be called to process RTOS kernel-related events. You do not need to recompile the source code when the kernel is replaced.

The RTOS object control block definition needs to be called for static object allocation. The implementation header file (os_xx.h in the following figure) provides access to such control block definitions. In the OpenHarmony LiteOS-M kernel, the header files whose names start with los_ provide the definitions of the kernel.

Development Example

#include ...
#include "cmsis_os2.h"

/*----------------------------------------------------------------------------
 * Application main thread
 *---------------------------------------------------------------------------*/
void app_main (void *argument) {
  // ...
  for (;;) {}
}

int main (void) {
  // System initialization
  MySystemInit();
  // ...

  osKernelInitialize();                // Initialize CMSIS-RTOS.
  osThreadNew(app_main, NULL, NULL);   // Create the main thread of the application.
  osKernelStart();                     // Start to execute the thread.
  for (;;) {}
}

POSIX

Basic Concepts

The OpenHarmony kernel uses the musl libc library and self-developed APIs and supports the Portable Operating System Interface (POSIX). You can develop components and applications working on the kernel based on the POSIX.

Development Guidelines

Available APIs

Table 11 APIs for process management

Header FileAPIDescription
#include <stdlib.h>void abort(void);Terminates the thread.
#include <assert.h>void assert(scalar expression);Terminates the thread if the assertion is false.
#include <pthread.h>int pthread_cond_destroy(pthread_cond_t *cond);Destroys a condition variable.
#include <pthread.h>int pthread_cond_init(pthread_cond_t *restrict cond, const pthread_condattr_t *restrict attr);Initializes a condition variable.
#include <pthread.h>int pthread_cond_timedwait(pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex, const struct timespec *restrict abstime);Waits for the condition.
#include <pthread.h>int pthread_condattr_init(pthread_condattr_t *attr);Initializes the condition variable attribute.
#include <pthread.h>int pthread_mutex_unlock(pthread_mutex_t *mutex);Unlocks a mutex.
#include <pthread.h>int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg);Creates a thread.
#include <pthread.h>int pthread_join(pthread_t thread, void **retval);Waits for a thread to terminate.
#include <pthread.h>pthread_t pthread_self(void);Obtains the ID of the current thread.
#include <pthread.h>int pthread_getschedparam(pthread_t thread, int *policy, struct sched_param *param);Obtains the scheduling policy and parameters of a thread.
#include <pthread.h>int pthread_setschedparam(pthread_t thread, intpolicy, const struct sched_param *param);Sets a scheduling policy and parameters for a thread.
#include <pthread.h>int pthread_mutex_init(pthread_mutex_t *_restrict m, const pthread_mutexattr_t *__restrict a);Initializes a mutex.
#include <pthread.h>int pthread_mutex_lock(pthread_mutex_t *m);Locks a mutex.
#include <pthread.h>int pthread_mutex_trylock(pthread_mutex_t *m);Attempts to lock a mutex.
#include <pthread.h>int pthread_mutex_destroy(pthread_mutex_t *m);Destroys a mutex.
#include <pthread.h>int pthread_attr_init(pthread_attr_t *attr);Initializes a thread attribute object.
#include <pthread.h>int pthread_attr_destroy(pthread_attr_t *attr);Destroys a thread attribute object.
#include <pthread.h>int pthread_attr_getstacksize(const pthread_attrt *attr, sizet *stacksize);Obtains the stack size of a thread attribute object.
#include <pthread.h>int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);Sets the stack size for a thread attribute object.
#include <pthread.h>int pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param);Obtains scheduling parameter attributes of a thread attribute object.
#include <pthread.h>int pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param);Sets scheduling parameter attributes for a thread attribute object.
#include <pthread.h>int pthread_getname_np(pthread_t pthread, char*name, size_t len);Obtains the thread name.
#include <pthread.h>int pthread_setname_np(pthread_t pthread, constchar *name);Sets the thread name.
#include <pthread.h>int pthread_cond_broadcast(pthread_cond_t *c);Unblocks all threads that are currently blocked on the condition variable cond.
#include <pthread.h>int pthread_cond_signal(pthread_cond_t *c);Unblocks a thread.
#include <pthread.h>int pthread_cond_wait(pthread_cond_t *__restrictc, pthread_mutex_t *__restrict m);Waits for the condition.

Table 12 APIs for file system management

Header FileAPIDescription
#include <libgen.h>char *dirname(char *path);Obtains the directory name.
#include <dirent.h>struct dirent *readdir(DIR *dirp);Reads a directory.
#include <sys/stat.h>int stat(const char *restrict path, struct stat *restrict buf);Obtains file information.
#include <unistd.h>int unlink(const char *pathname);Deletes a file.
#include <fcntl.hint open(const char *path, int oflags, ...);Opens a file. If the file does not exist, create a file and open it.
#include <nistd.h>int close(int fd);Closes a file.
#include <stdio.h>int rename(const char *oldpath, const char *newpath);Renames a file.
#include <dirent.h>DIR *opendir(const char *dirname);Opens the specified directory.
#include <dirent.h>int closedir(DIR *dir);Closes the specified directory.
#include <sys/mount.h>int mount(const char *source, const char *target, const char *filesystemtype, unsigned long mountflags, const void *data);Mounts a file system.
#include <sys/mount.h>int umount(const char *target);Unmounts a file system.
#include <sys/mount.h>int umount2(const char *target, int flag);Unmounts a file system.
#include <sys/stat.h>int fsync(int fd);Synchronizes the file associated with the specified file descriptor to the storage device.
#include <sys/stat.h>int mkdir(const char *pathname, mode_t mode);Creates a directory.
#include <unistd.h>int rmdir(const char *path);Deletes a directory.
#include <sys/stat.h>int fstat(int fd, struct stat *buf);Obtains file status.
#include <sys/statfs.h>int statfs(const char *path, struct statfs *buf);Obtains the file system information for a file in a specified path.

Table 13 APIs for time management

Header FileAPIDescription
#include <sys/time.h>int gettimeofday(struct timeval *tv, struct timezone *tz);Obtains the time. Currently, time zone is not supported, and the return value of tz is empty.
#include <time.h>struct tm *gmtime(const time_t *timep);Converts the date and time to broken-down time or ASCII.
#include <time.h>struct tm *localtime(const time_t *timep);Obtains the local time.
#include <time.h>struct tm *localtime_r(const time_t *timep, struct tm *result);Obtains the local time.
#include <time.h>time_t mktime(struct tm *tm);Converts the date and time to broken-down time or ASCII.
#include <time.h>size_t strftime(char *s, size_t max, const char *format,const struct tm *tm);Formats the date and time.
#include <time.h>time_t time(time_t *tloc);Obtains the calendar time.
#include <sys/times.h>clock_t times(struct tms *buf);Obtains the thread time.
#include <unistd.h>int usleep(useconds_t usec);Goes to hibernation, in microseconds.
#include <time.h>int nanosleep(const struct timespec *tspec1, structtimespec *tspec2);Suspends the current thread till the specified time.
#include <time.h>int clock_gettime(clockid_t id, struct timespec *tspec);Obtains the clock time.
#include <time.h>int timer_create(clockid_t id, struct sigevent *__restrict evp, timer_t *__restrict t);Creates a timer for a thread.
#include <time.h>int timer_delete(timer_t t);Deletes the timer for a thread.
#include <time.h>int timer_settime(timer_t t, int flags, const struct itimerspec *__restrict val, struct itimerspec *_restrict old);Sets a timer for a thread.
#include <time.h>time_t time (time_t *t);Obtains the time.
#include <time.h>char *strptime(const char *s, const char *format, struct tm *tm);Converts the time string into the time tm structure.

Table 14 APIs for util

Header FileAPIDescription
#include <stdlib.h>int atoi(const char *nptr);Converts a string into an integer (int type).
#include <stdlib.h>long atol(const char *nptr);Converts the string into a long Integer (long type).
#include <stdlib.h>long long atoll(const char *nptr);Converts a string into a long longer integer (long long type).
#include <ctype.h>int isalnum(int c);Checks whether the passed character is alphanumeric.
#include <ctype.h>int isascii(int c);Checks whether the passed character is an ASCII character.
#include <ctype.h>int isdigit(int c);Checks whether the passed character is a digit.
#include <ctype.h>int islower(int c);Checks whether the passed character is in lowercase.
#include <ctype.h>int isprint(int c);Checks whether the passed character is printable, including spaces.
#include <ctype.h>int isspace(int c);Checks whether the passed character is a white-space character.
#include <ctype.h>int isupper(int c);Checks whether the passed character is in uppercase.
#include <ctype.h>int isxdigit(int c);Checks whether the passed character is a hexadecimal number.
#include <stdlib.h>long int random (void);Generates a pseudo-random number.
#include <stdlib.h>void srandom(unsigned int seed);Initializes the random number generator.
#include <ctype.h>int tolower(int c);Converts the given letter to lowercase.
#include <ctype.h>int toupper(int c);Converts the given letter to uppercase.
#include <stdarg.h>type va_arg(va_list ap, type);Retrieves the next argument in the parameter list with type.
#include <stdarg.h>void va_copy(va_list dest, va_list src);Copies parameters.
#include <stdarg.h>void va_end(va_list ap);Clears the variable list.
#include <stdarg.h>void va_start(va_list ap, last);Defines the beginning of the list of variable arguments.
#include <string.h>char *strchr(const char *s, int c);Searches for a character in a string.
#include <string.h>int strcmp(const char *s1, const char *s2);Compares two strings.
#include <string.h>size_t strcspn(const char *s, const char *reject);Obtains the length of the initial segment of the string s which does not contain any of bytes in the string reject.
#include <string.h>char *strdup(const char *s);Copies a string to a new position.
#include <string.h>size_t strlen(const char *s);Obtains the length of a string.
#include <strings.h>int strncasecmp(const char *s1, const char *s2, size_t n);Compares the bytes of the specified length in two strings, ignoring case.
#include <strings.h>int strcasecmp(const char *s1, const char *s2);Compares two strings, ignoring case.
#include <string.h>int strncmp(const char *s1, const char *s2, size_t n);Compares the bytes of the specified length in two strings.
#include <string.h>char *strrchr(const char *s, int c);Searches for a character in a string.
#include <string.h>char *strstr(const char *haystack, const char *needle);Searches for the specified substring in a string.
#include <stdlib.h>long int strtol(const char *nptr, char **endptr, int base);Converts the string pointed to by nptr into a long int value according to the given base.
#include <stdlib.h>unsigned long int strtoul(const char *nptr, char**endptr, int base);Converts a string into an unsigned long integer.
#include <stdlib.h>unsigned long long int strtoull(const char *nptr,char **endptr,int base);Converts a string into an unsigned long long integer.
#include <regex.h>int regcomp(regex_t *preg, const char *regex,int cflags);Compiles a regular expression.
#include <regex.h>int regexec(const regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags);Executes the compiled regular expression.
#include <regex.h>void regfree(regex_t *preg);Releases the regular expression.
#include <string.h>char *strerror(int errnum);Obtains an error message string of the specified error code.

Table 15 APIs for math operations

Header FileAPIDescription
#include <stdlib.h>int abs(int i);Obtains the absolute value.
#include <math.h>double log(double x);Obtains the natural logarithm (base-e logarithm) of x.
#include <math.h>double pow(double x, double y);Obtains x raised to the power of y.
#include <math.h>double round(double x);Rounds off the value from zero to the nearest integer.
#include <math.h>double sqrt(double x);Obtains the square root of x.

Table 16 APIs for I/O operations

Header FileAPIDescription
#include <stdio.h>void clearerr(FILE *stream);Clears the file end and error indication of a stream.
#include <stdio.h>int fclose(FILE *stream);Closes a file stream.
#include <stdio.h>FILE *fdopen(int fd, const char *mode);Opens a file stream based on the file descriptor.
#include <stdio.h>int feof(FILE *stream);Checks the end-of-file indicator for a stream.
#include <stdio.h>int fflush(FILE *stream);Flushes a stream.
#include <stdio.h>char *fgets(char *s, int size, FILE *stream);Reads the next line of a stream.
#include <stdio.h>int fileno(FILE *stream);Obtains the file descriptor for a stream.
#include <stdio.h>FILE *fopen(const char *path, const char *mode);Opens a stream.
#include <stdio.h>int fputs(const char *s, FILE *stream);Writes a line to the specified stream.
#include <stdio.h>size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);Reads a stream.
#include <stdio.h>int fseek(FILE *stream, long offset, int whence);Sets the position of the stream pointer.
#include <stdio.h>long ftell(FILE *stream);Obtains the position of the stream pointer.
#include <stdio.h>size_t fwrite(const void *ptr, size_t size, size_tnmemb, FILE *stream);Writes data to a stream.
#include <stdio.h>void perror(const char *s);Prints system error information.
#include <stdio.h>void rewind(FILE *stream);Sets the position to the beginning of the file of the specified stream.
#include <unistd.h>ssize_t write(int fd, const void *buf, size_t size);Writes data a file.
#include <unistd.h>ssize_t read(int fd, void *buf, size_t size);Reads data from a file.

Table 17 APIs for network

Header FileAPIDescription
#include <sys/socket.h>void freeaddrinfo(struct addrinfo *res);Releases the dynamic memory allocated using getaddrinfo.
#include <sys/socket.h>int getaddrinfo(const char *restrict nodename, constchar *restrict servname, const struct addrinfo *restricthints, struct addrinfo **restrict res);Obtains a list of IP addresses and port numbers for the specified host and service.
#include <sys/socket.h>int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, char *restrict node, socklen_t nodelen, char *restrict service, socklen_t servicelen, int flags);Converts a socketaddr structure to a pair of host name and service strings.
#include <net/if.h>unsigned int if_nametoindex(const char *ifname);Obtains the index based on the network port name.
#include <arpa/inet.h>in_addr_t inet_addr(const char *cp);Converts the network host address in dotted decimal notation to binary format.
#include <arpa/inet.h>char *inet_ntoa(struct in_addr in);Converts the network host address in binary format to dotted decimal notation.
#include <arpa/inet.h>const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);Converts the network address in standard text format to numeric binary format.
#include <arpa/inet.h>int inet_pton(int af, const char *src, void *dst);Converts the network address in standard text format to numeric binary format.
#include <sys/socket.h>int listen(int sockfd, int backlog);Listens for connections on a socket.
#include <sys/socket.h>ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags);Receives a message from a socket. Currently, only the scenario with iov of 1 is supported and ancillary messages are not supported.
#include <sys/socket.h>ssize_t send(int sockfd, const void *buf, size_t len, int flags);Sends a message on a socket.
#include <sys/socket.h>ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags);Sends a message on a socket. Ancillary messages are not supported.
#include <sys/socket.h>ssize_t sendto(int sockfd, const void *buf, size_t len, intflags,const struct sockaddr *dest_addr, socklen_t addrlen);Sends a message on a socket.
#include <sys/socket.h>int setsockopt(int sockfd, int level, int optname,constvoid *optval, socklen_t optlen);Sets options associated with a socket.

Table 18 APIs for memory management

Header FileAPIDescription
#include <string.h>int memcmp(const void *s1, const void *s2, size_t n);Compares successive elements from two arrays until it finds elements that are different.
#include <string.h>void *memcpy(void *dest, const void *src, size_t n);Copies n bytes from the source memory area pointed to by src to the destination memory area pointed to by dest.
#include <string.h>void *memset(void *s, int c, size_t n);Initializes memory.
#include <stdlib.h>void *realloc(void *ptr, size_t size);Reallocates memory.
#include <stdlib.h>void *malloc(size_t size);Dynamically allocates memory blocks.
#include <stdlib.h>void free(void *ptr);Release the memory space pointed to by ptr.

Table 19 APIs for IPC

Header FileAPIDescription
#include <semaphore.h>int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout);Locks the semaphore referenced by sem as in the sem_wait() function.
#include <semaphore.h>int sem_destroy(sem_t *sem);Destroys the specified unnamed semaphore.
#include <semaphore.h>int sem_init(sem_t *sem, int pshared, unsigned int value);Creates and initializes an unnamed semaphore.
#include <semaphore.h>int sem_post(sem_t *sem);Increments the semaphore count by 1.
#include <semaphore.h>int sem_wait(sem_t *sem);Obtains the semaphore.
#include <mqueue.h>mqd_t mq_open(const char *mqName, int openFlag, ...);Opens an existing message queue with the specified name or creates a message queue.
#include <mqueue.h>int mq_close(mqd_t personal);Closes a message queue with the specified descriptor.
#include <mqueue.h>int mq_unlink(const char *mqName);Deletes the message queue of the specified name.
#include <mqueue.h>int mq_send(mqd_t personal, const char *msg, size_t msgLen, unsigned int msgPrio);Puts a message with the specified content and length into a message queue.
#include <mqueue.h>ssize_t mq_receive(mqd_t personal, char *msg, size_t msgLen, unsigned int *msgPrio);Deletes the oldest message from a message queue and puts it in the buffer pointed to by msg_ptr.
#include <mqueue.h>int mq_timedsend(mqd_t personal, const char*msg, size_t msgLen, unsigned int msgPrio, const struct timespec *absTimeout)Puts a message with the specified content and length into a message queue at the specified time.
#include <mqueue.h>ssize_t mq_timedreceive(mqd_t personal, char*msg, size_t msgLen, unsigned int *msgPrio, const struct timespec *absTimeout);Obtains a message with the specified content and length from a message queue.
#include <mqueue.h>int mq_setattr(mqd_t mqdes, const struct mq_attr *__restrict newattr, struct mq_attr *__restrict oldattr);Sets the message queue attributes specified by the descriptor.
#include <libc.h>const char *libc_get_version_string(void);Obtains the libc version string.
#include <libc.h>int libc_get_version(void);Obtains the libc version.

Error Codes

The table below lists common error codes.

Error CodeValueDescription
ENOERR0Success
EPERM1Operation not permitted
ENOENT2No such file or directory
ESRCH3No such process
EINTR4Interrupted system call
EIO5I/O error
ENXIO6No such device or address
E2BIG7Arg list too long
ENOEXEC8Exec format error
EBADF9Bad file number
ECHILD10No child processes
EAGAIN11Try again
ENOMEM12Out of memory
EACCES13Permission denied
EFAULT14Bad address
ENOTBLK15Block device required
EBUSY16Device or resource busy
EEXIST17File exists
EXDEV18Cross-device link
ENODEV19No such device
ENOTDIR20Not a directory
EISDIR21Is a directory
EINVAL22Invalid argument
ENFILE*23File table overflow
EMFILE24Too many open files
EFBIG27File too large
ENOSPC28No space left on device
ESPIPE29Illegal seek
EROFS30Read-only file system
EMLINK31Too many links
EDOM33Math argument out of domain
ERANGE34Math result not representable
EDEADLK35Resource deadlock would occur
ENAMETOOLONG36Filename too long
ENOLCK37No record locks available
ENOSYS38Function not implemented
ENOTEMPTY39Directory not empty
ELOOP40Too many symbolic links encountered
ENOMSG42No message of desired type
EIDRM43Identifier removed
ELNRNG48Link number out of range
EBADR53Invalid request descriptor
EBADRQC56Invalid request code
ENOSTR60Device not a stream
ENODATA61No data available
ETIME62Timer expired
EPROTO71Protocol error
EBADMSG74Not a data message
EOVERFLOW75Value too large for defined data type
EMSGSIZE90Message too long

Development Example

Example:

Creates a thread, transfers the information in the parent thread to the child thread, and prints the transferred information and the thread ID in the child thread.

The sample code can be compiled and verified in ./kernel/liteos_m/testsuites/src/osTest.c. The DemoForTest function is called in TestTaskEntry.

#include <stdio.h>
#include <pthread.h>

pthread_t ntid;

void *ThreadFn(void *arg)
{
    pthread_t tid;
    while(1) {
        tid = pthread_self();
        printf("\n++++++++++++++  %s  %s  tid = %d ++++++++++++++\n", (char*)arg, __FUNCTION__, tid);
    }
    return ((void *)0);
}

void DemoForTest()
{
    int err;
    char* str = "Hello world";
    err = pthread_create(&ntid, NULL, ThreadFn, (void*)str);
    if(err != 0) {
        printf("can't create thread\n");
    }
}

The execution result of DemoForTest is as follows:

++++++++++++++  Hello world  ThreadFn  tid = 48 ++++++++++++++

++++++++++++++  Hello world  ThreadFn  tid = 48 ++++++++++++++

++++++++++++++  Hello world  ThreadFn  tid = 48 ++++++++++++++

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Kernel

harmony 鸿蒙Kernel Coding Specification

harmony 鸿蒙Interrupt Management

harmony 鸿蒙Event

harmony 鸿蒙Mutex

harmony 鸿蒙Queue

harmony 鸿蒙Semaphore

harmony 鸿蒙Doubly Linked List

harmony 鸿蒙Memory Management

harmony 鸿蒙Software Timer

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/cae4d15abe154716837ef3aa3a0e2577