How can I find the value of LC_XXX locale integral constants so that I can use them with cffi

I have this code:

(define-foreign-library libc
  (:unix "libc.so.6"))
(use-foreign-library libc)
(defcfun "setlocale" :pointer (category :int) (locale :pointer)) 

I want too:

(with-foreign-string (locale "en_US.UTF-8")
    (setlocale XXXX locale))

How can I find the integer values ​​of various LC_xxx constants to pass them to the call above? Is there a better way to achieve this?

+3
source share
2 answers

I see this in my locale.h:

/* These are the possibilities for the first argument to setlocale.
   The code assumes that the lowest LC_* symbol has the value zero.  */
#define LC_CTYPE          __LC_CTYPE
#define LC_NUMERIC        __LC_NUMERIC
#define LC_TIME           __LC_TIME
#define LC_COLLATE        __LC_COLLATE
#define LC_MONETARY       __LC_MONETARY
#define LC_MESSAGES       __LC_MESSAGES
#define LC_ALL            __LC_ALL
#define LC_PAPER          __LC_PAPER
#define LC_NAME           __LC_NAME
#define LC_ADDRESS        __LC_ADDRESS
#define LC_TELEPHONE      __LC_TELEPHONE
#define LC_MEASUREMENT    __LC_MEASUREMENT
#define LC_IDENTIFICATION __LC_IDENTIFICATION

and bits / locale.h contains:

enum
{
  __LC_CTYPE = 0,
  __LC_NUMERIC = 1,
  __LC_TIME = 2,
  __LC_COLLATE = 3,
  __LC_MONETARY = 4,
  __LC_MESSAGES = 5,
  __LC_ALL = 6,
  __LC_PAPER = 7,
  __LC_NAME = 8,
  __LC_ADDRESS = 9,
  __LC_TELEPHONE = 10,
  __LC_MEASUREMENT = 11,
  __LC_IDENTIFICATION = 12
};

You can simply compile a C program that prints them. This is what groveller does.

+1
source

You must re-declare constants in your Lisp code. In fact, CFFI can do this for you .

+2
source

All Articles