新的轉碼方法 , libiconv , BIG5 轉 UTF8

這段 code , 很好用, 就貼在這兒了, 下次可以直接剪下跟貼上

重點有兩個:

1. From encoding 是 CP950

2. libiconv 不要用 libc 的, 因為缺一個 function : iconvctl

int fnConvert(const char *from, const char *to, char* save, int savelen, char *src, int srclen)
{
    iconv_t cd;
    char   *inbuf = src;
    char *outbuf = save;
    size_t outbufsize = savelen;
    int status = 0;
    size_t  savesize = 0;
    size_t inbufsize = srclen+1;
    char* inptr = inbuf;
    size_t      insize = inbufsize;
    char* outptr = outbuf;
    size_t outsize = outbufsize;

    if ( ( cd = iconv_open(to, from) ) == (iconv_t)-1 )
    {
        status = -1;
        goto done;
    }

    iconv(cd,NULL,NULL,NULL,NULL);
    if (inbufsize == 0)
    {
        status = -1;
        goto done;
    }
    while (insize > 0)
    {
        size_t res = iconv(cd, &inptr,&insize,&outptr,&outsize);
        if (outptr != outbuf)
        {
            int saved_errno = errno;
            int outsize = outptr - outbuf;
            strncpy(save+savesize, outbuf, outsize);
            errno = saved_errno;
        }
        if (res == (size_t)(-1))
        {
            if (errno == EILSEQ)
            {
                int one = 1;
                iconvctl(cd,ICONV_SET_DISCARD_ILSEQ,&one);
                status = -3;
            }
            else if (errno == EINVAL)
            {
                if (inbufsize == 0)
                {
                    status = -4;
                    goto done;
                }
                else
                {
                    break;
                }
            }
            else if (errno == E2BIG)
            {
                status = -5;
                goto done;
            }
            else
            {
                status = -6;
                goto done;
            }
        }
    }
    status = strlen(save);
done:
    iconv_close(cd);
    return status;
}

EXAMPLE:
int fnB2U( unsigned char *str )
{
    int srclen, destlen, status;
    unsigned char tmp[2048];

    status = -1;
    if ( ( srclen = strlen( str ) ) == 0 )
        return status;
    destlen  = sizeof( unsigned char ) * ( srclen * 2 ) + 1;
    tmp[0] = '';
    if ( ( status = fnConvert ( "CP950", "UTF-8", tmp, destlen, str, srclen) ) > 0 )
        strcpy( str, tmp);
    else
        printf( "status = %dn");
    return( status);
}

Google 的 server 照片 , data center ,

來源 :
http://news.cnet.com/8301-1001_3-10209580-92.html

http://www.datacenterknowledge.com/archives/2009/04/01/googles-custom-web-server-revealed/

不過發表日是 April fool 😛 , 這是玩笑嗎?

誰可以估算一下 Google 一台 server 多少錢呢?

MB : GIGABYTE , GA-9IVDP , 這張主板很小/精簡 , 甚至顯示卡/晶片都沒用, 側面有看到 USB port.
CPU : 2 * ? , CPU 也應該很小, 風扇/散熱片都那麼小
RAM : 8 * 1GB (我猜的, RAM太少不好用)
HD : SATA * 2 ( 目前 300G – 500G , CP值較高, 兩顆可能做 RAID 1 , mirror)
電源 : 可能要 300W 吧, 不過是特殊規格, 放大照片看是 MIC , AC 220伏特 , DC 13.65V , 20.5A
電池 : 不知

特別的是, 他們的 HD 等元件都是用魔鬼氈綁住的.

CENTOS 改 keyboard mapping

system-config-keyboard

改 IP address

工具 : system-config-network

或改 /etc/sysconfig/network-scripts/ifcfg-eth0 檔案

改完後, 下
/etc/init.d/network restart

service network restart

—–

centos 改 init.d 的 run level 的方法: chkconfig

列出 各 service :

chkconfig –list