FreeBASIC  0.91.0
drv_intl_getweekdayname.c
Go to the documentation of this file.
1 /* get localized weekday name */
2 
3 #include "../fb.h"
4 #include <langinfo.h>
5 
6 FBSTRING *fb_DrvIntlGetWeekdayName( int weekday, int short_names )
7 {
8  const char *pszName;
9  FBSTRING *result;
10  size_t name_len;
11  nl_item index;
12 
13  if( weekday < 1 || weekday > 7 )
14  return NULL;
15 
16  if( short_names ) {
17  index = (nl_item) (ABDAY_1 + weekday - 1);
18  } else {
19  index = (nl_item) (DAY_1 + weekday - 1);
20  }
21 
22  FB_LOCK();
23 
24  pszName = nl_langinfo( index );
25  if( pszName==NULL ) {
26  FB_UNLOCK();
27  return NULL;
28  }
29 
30  name_len = strlen( pszName );
31 
32  result = fb_hStrAllocTemp( NULL, name_len );
33  if( result!=NULL ) {
34  FB_MEMCPY( result->data, pszName, name_len + 1 );
35  }
36 
37  FB_UNLOCK();
38 
39  return result;
40 }