diff options
author | Christopher Faylor <me@cgf.cx> | 2007-08-02 14:21:53 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2007-08-02 14:21:53 +0000 |
commit | 7e4f1942e4a3a3d1477dcffd5b45255007ed13d4 (patch) | |
tree | cdb98f9b9bfed984b579b0f6decc25a715ee0cac /winsup/cygwin/strfuncs.cc | |
parent | dcd1ef4516bf43cdd866069ef5df2a6a958945d2 (diff) | |
download | cygnal-7e4f1942e4a3a3d1477dcffd5b45255007ed13d4.tar.gz cygnal-7e4f1942e4a3a3d1477dcffd5b45255007ed13d4.tar.bz2 cygnal-7e4f1942e4a3a3d1477dcffd5b45255007ed13d4.zip |
* dcrt0.cc (codepage_type): Remove definition.
* strfuncs.cc: Move it here. New file with bits of miscfuncs.cc.
* miscfuncs.cc: Remove wide character stuff.
Diffstat (limited to 'winsup/cygwin/strfuncs.cc')
-rw-r--r-- | winsup/cygwin/strfuncs.cc | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/winsup/cygwin/strfuncs.cc b/winsup/cygwin/strfuncs.cc new file mode 100644 index 000000000..c0029fb1f --- /dev/null +++ b/winsup/cygwin/strfuncs.cc @@ -0,0 +1,43 @@ +/* strfuncs.cc: misc funcs that don't belong anywhere else + + Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, + 2005, 2006, 2007 Red Hat, Inc. + +This file is part of Cygwin. + +This software is a copyrighted work licensed under the terms of the +Cygwin license. Please consult the file "CYGWIN_LICENSE" for +details. */ + +#include "winsup.h" +#include <winbase.h> +#include <winnls.h> + +codepage_type current_codepage = ansi_cp; + +UINT +get_cp () +{ + return current_codepage == ansi_cp ? GetACP() : GetOEMCP(); +} + +/* tlen is always treated as the maximum buffer size, including the '\0' + character. sys_wcstombs will always return a 0-terminated result, no + matter what. */ +int __stdcall +sys_wcstombs (char *tgt, int tlen, const WCHAR *src, int slen) +{ + int ret; + + ret = WideCharToMultiByte (get_cp (), 0, src, slen, tgt, tlen, NULL, NULL); + if (ret) + tgt[ret < tlen ? ret : tlen - 1] = '\0'; + return ret; +} + +int __stdcall +sys_mbstowcs (WCHAR *tgt, const char *src, int len) +{ + int res = MultiByteToWideChar (get_cp (), 0, src, -1, tgt, len); + return res; +} |