Читаем Programming with POSIX® Threads полностью

13 #ifndef LOGIN_NAME_MAX

14 # define LOGIN_NAME_MAX 32

15 #endif

16

17 int main (int argc, char *argv[])

18 {

19 char login_str[LOGIN_NAME_MAX];

20 char stdin_str[TTY_NAME_MAX];

21 char cterm_str[L_ctermid], *cterm_str_ptr;

22 int status;

23

24 status = getlogin_r (login_str, sizeof (login_str));

25 if (status != 0)

26 err_abort (status, "Get login");

27 cterm_str_ptr = ctermid (cterm_str);

28 if (cterm_str_ptr == NULL)

29 errno_abort ("Get cterm");

30 status = ttyname_r (0, stdin_str, sizeof (stdin_str));

31 if (status != 0)

32 err_abort (status, "Get stdin");

33 printf ("User: %s, cterm: %s, fd 0: %s\n",

34 login_str, cterm_str, stdin_str);

35 return 0;

<p><strong>6.5.2 Directory searching</strong></p>

int readdir_r (DIR *dirp, struct dirent *entry, struct dirent **result);

This function performs essentially the same action as readdir. That is, it returns the next directory entry in the directory stream specified by dirp. The difference is that instead of returning a pointer to that entry, it copies the entry into the buffer specified by entry. On success, it returns 0 and sets the pointer specified by result to the buffer entry. On reaching the end of the directory stream, it returns 0 and sets result to NULL. On failure, it returns an error number such as

EBADF.

Refer to program pipe .c, in Section 4.1, for a demonstration of using readdir_r to allow your threads to search multiple directories concurrently.

<p>6.5.3 String token</p>

char *strtok_r ( char *s, const char *sep, char **lasts);

This function returns the next token in the string s. Unlike strtok, the context (the current pointer within the original string) is maintained in lasts, which is specified by the caller, rather than in a static pointer internal to the function.

In the first call of a series, the argument s gives a pointer to the string. In subsequent calls to return successive tokens of that string, s must be specified as NULL. The value lasts is set by strtok_r to maintain the function's position within the string, and on each subsequent call you must return that same value of lasts. The strtok_r function returns a pointer to the next token, or NULL when there are no more tokens to be found in the original string.

<p>6.5.4 Time representation</p>

char *asctime_r (const struct tm *tm, char *buf);

char *ctime_r (const time_t *clock, char *buf);

struct tm *gmtime_r (const time_t *clock, struct tm *result);

struct tm *localtime_r (const time_t *clock, struct tm *result);

The output buffers (buf and result) are supplied by the caller, instead of returning a pointer to static storage internal to the functions. Otherwise, they are identical to the traditional variants. The asctime_r and ctime_r routines, which return ASCII character representations of a system time, both require that their buf argument point to a character string of at least 26 bytes.

<p>6.5.5 Random number generation</p>

int rand_r (unsigned int *seed);

The seed is maintained in caller-supplied storage (seed) rather than using static storage internal to the function. The main problem with this interface is that it is not usually practical to have a single seed shared by all application and library code within a program. As a result, the application and each library will generally have a separate "stream" of random numbers. Thus, a program converted to use rand_r instead of rand is likely to generate different results, even if no threads are created. (Creating threads would probably change the order of calls to rand, and therefore change results anyway.)

<p>6.5.6 Group and user database</p>

Group database:

int getgrgid_r (gid_t gid, struct group *grp, char *buffer,

size_t bufsize, struct group **result);

int getgrnam_r (

const char *name, struct group *grp,

Перейти на страницу:

Похожие книги

1С: Бухгалтерия 8 с нуля
1С: Бухгалтерия 8 с нуля

Книга содержит полное описание приемов и методов работы с программой 1С:Бухгалтерия 8. Рассматривается автоматизация всех основных участков бухгалтерии: учет наличных и безналичных денежных средств, основных средств и НМА, прихода и расхода товарно-материальных ценностей, зарплаты, производства. Описано, как вводить исходные данные, заполнять справочники и каталоги, работать с первичными документами, проводить их по учету, формировать разнообразные отчеты, выводить данные на печать, настраивать программу и использовать ее сервисные функции. Каждый урок содержит подробное описание рассматриваемой темы с детальным разбором и иллюстрированием всех этапов.Для широкого круга пользователей.

Алексей Анатольевич Гладкий

Программирование, программы, базы данных / Программное обеспечение / Бухучет и аудит / Финансы и бизнес / Книги по IT / Словари и Энциклопедии
1С: Управление торговлей 8.2
1С: Управление торговлей 8.2

Современные торговые предприятия предлагают своим клиентам широчайший ассортимент товаров, который исчисляется тысячами и десятками тысяч наименований. Причем многие позиции могут реализовываться на разных условиях: предоплата, отсрочка платежи, скидка, наценка, объем партии, и т.д. Клиенты зачастую делятся на категории – VIP-клиент, обычный клиент, постоянный клиент, мелкооптовый клиент, и т.д. Товарные позиции могут комплектоваться и разукомплектовываться, многие товары подлежат обязательной сертификации и гигиеническим исследованиям, некондиционные позиции необходимо списывать, на складах периодически должна проводиться инвентаризация, каждая компания должна иметь свою маркетинговую политику и т.д., вообщем – современное торговое предприятие представляет живой организм, находящийся в постоянном движении.Очевидно, что вся эта кипучая деятельность требует автоматизации. Для решения этой задачи существуют специальные программные средства, и в этой книге мы познакомим вам с самым популярным продуктом, предназначенным для автоматизации деятельности торгового предприятия – «1С Управление торговлей», которое реализовано на новейшей технологической платформе версии 1С 8.2.

Алексей Анатольевич Гладкий

Финансы / Программирование, программы, базы данных