关于catopen函数:

参考网址:http://pubs.opengroup.org/onlinepubs/009695399/functions/catopen.html

1)编辑消息文件

[root@Master catlogTest]# vi msg1.euc

1 Hello msg1.euc 1

2 Hello msg2.euc 2

3 Hello msg3.euc 3

4 Hello msg4.euc 4

[root@Master catlogTest]# vi msg1.sjis

1 Hello msg1.sjis 1

2 Hello msg2.sjis 2

3 Hello msg3.sjis 3

4 Hello msg4.sjis 4

2)用gencat生成cat文件

[root@Master catlogTest]# gencat msg1.euc.cat msg1.euc

[root@Master catlogTest]# ls

msg1.euc  msg1.euc.cat  msg1.sjis

[root@Master catlogTest]# gencat msg2.sjis.cat msg1.sjis

[root@Master catlogTest]# ls

msg1.euc  msg1.euc.cat  msg1.sjis  msg2.sjis.cat

3)使用catopen等函数调用消息

#include <stdio.h>

#include <locale.h>

#include <nl_types.h>

int main()

{

nl_catd catid = NULL;

char *fstr;

char *s1;

setlocale(LC_ALL,"");

catid = catopen("/root/honglihua/catlogTest/msg1.euc.cat",NL_CAT_LOCALE);

if((int)catid == -1)

{

fprintf(stdout,":Can't open message catlog");

return -1;

}

fstr = (char *)catgets(catid,1,1,"default string");

fprintf(stdout,"%s\n",fstr);

catclose(catid);

return 0;

}

编译:

[root@Master catlogTest]# gcc -o catopenTest catopenTest.c

执行:

[root@Master catlogTest]# ./catopenTest

Hello msg1.euc 1

如果

fstr = (char *)catgets(catid,1,2,"default string");

执行结果为:

[root@Master catlogTest]# ./catopenTest

Hello msg2.euc 2

如果catopen第一个参数不带路径,则可以设置NLSPATH环境变量如下:
setenv NLSPATH /usr/lib/locale/%L/LC_MESSAGES/%N
(%L会被$LANG代替;%N会被catopen中的hello代替)
在调用:
catopen("hello", NL_CAT_LOCALE)时,
会去/usr/lib/locale/en_US/LC_MESSAGES/hello
这个路径寻找消息文件

补充:

经过测试,得出当catopen的满足如下条件值时, %L会按照LC_ALL > LC_MESSAGES > LANG的优先值顺序进行替换。

1)catopen的第一个参数不为路径

2)catopen的第二个参数为NL_CAT_LOCALE(如果第二个参数为0,%L会被$LANG代替)

3)设置了环境变量NLSPATH,且该变量所指的路径中使用%L

关于catopen函数的更多相关文章

  1. Python 小而美的函数

    python提供了一些有趣且实用的函数,如any all zip,这些函数能够大幅简化我们得代码,可以更优雅的处理可迭代的对象,同时使用的时候也得注意一些情况   any any(iterable) ...

  2. 探究javascript对象和数组的异同,及函数变量缓存技巧

    javascript中最经典也最受非议的一句话就是:javascript中一切皆是对象.这篇重点要提到的,就是任何jser都不陌生的Object和Array. 有段时间曾经很诧异,到底两种数据类型用来 ...

  3. JavaScript权威指南 - 函数

    函数本身就是一段JavaScript代码,定义一次但可能被调用任意次.如果函数挂载在一个对象上,作为对象的一个属性,通常这种函数被称作对象的方法.用于初始化一个新创建的对象的函数被称作构造函数. 相对 ...

  4. C++对C的函数拓展

    一,内联函数 1.内联函数的概念 C++中的const常量可以用来代替宏常数的定义,例如:用const int a = 10来替换# define a 10.那么C++中是否有什么解决方案来替代宏代码 ...

  5. 菜鸟Python学习笔记第一天:关于一些函数库的使用

    2017年1月3日 星期二 大一学习一门新的计算机语言真的很难,有时候连函数拼写出错查错都能查半天,没办法,谁让我英语太渣. 关于计算机语言的学习我想还是从C语言学习开始为好,Python有很多语言的 ...

  6. javascript中的this与函数讲解

    前言 javascript中没有块级作用域(es6以前),javascript中作用域分为函数作用域和全局作用域.并且,大家可以认为全局作用域其实就是Window函数的函数作用域,我们编写的js代码, ...

  7. 复杂的 Hash 函数组合有意义吗?

    很久以前看到一篇文章,讲某个大网站储存用户口令时,会经过十分复杂的处理.怎么个复杂记不得了,大概就是先 Hash,结果加上一些特殊字符再 Hash,结果再加上些字符.再倒序.再怎么怎么的.再 Hash ...

  8. JS核心系列:浅谈函数的作用域

    一.作用域(scope) 所谓作用域就是:变量在声明它们的函数体以及这个函数体嵌套的任意函数体内都是有定义的. function scope(){ var foo = "global&quo ...

  9. C++中的时间函数

    C++获取时间函数众多,何时该用什么函数,拿到的是什么时间?该怎么用?很多人都会混淆. 本文是本人经历了几款游戏客户端和服务器开发后,对游戏中时间获取的一点总结. 最早学习游戏客户端时,为了获取最精确 ...

随机推荐

  1. LC 384. Shuffle an Array

    Shuffle a set of numbers without duplicates. Example: // Init an array with set 1, 2, and 3. int[] n ...

  2. LC 358. Rearrange String k Distance Apart

    Given a non-empty string s and an integer k, rearrange the string such that the same characters are ...

  3. numpy之填充为nan的数据为该列平均值

    # coding=utf-8 import numpy as np ''' 填充nan的数据,为该列的平均值 ''' def fill_ndarray(t1): for i in range(t1.s ...

  4. java回调函数详解

    声明:博客参考于https://www.cnblogs.com/yangmin86/p/7090882.html,谢谢哥们 回调函数:是指在A类执行代码时,调用了B类中的方法,但B类中的方法执行了A类 ...

  5. FAQ_2

    FAQ-2 1.LoadRunner超时错误: 在录制Web服务器端,如果超过120秒服务器协议脚本回放时超时情况经常出现,产生错误的原因也有很多,解决的方法也不同. 错误现象1:Action.c(1 ...

  6. Linux 服务器基本优化

    一:修改ulimit数 vi /etc/security/limits.conf 添加如下行: * soft noproc 65535 * hard noproc 65535 * soft nofil ...

  7. koa cookie使用

    1 .Koa 中设置 Cookie 的值 ctx.cookies.set(name, value, [options])  通过 options 置 设置 cookie name 的 value : ...

  8. docker笔记、常遇问题、常用命令

    启动一个容器并且进到里面,退出后,容器结束 [root@bogon ~]# docker run --name mynginx -it nginx 启动一个容器,退出后自动删除 [root@bogon ...

  9. 【HANA系列】SAP HANA SQL从给定日期中获取年份

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA SQL从给定日 ...

  10. javascript预编译练习(变态篇)

    例1. <!DOCTYPE html> <html> <head> <title></title> </head> <bo ...