88#include < cstdint>
99#include < cstdio>
1010#include < cstring>
11+ #include < fcitx-utils/fdstreambuf.h>
1112#include < fcitx-utils/log.h>
1213#include < fcitx-utils/misc.h>
1314#include < fcitx-utils/stringutils.h>
15+ #include < istream>
16+ #include < string>
1417
1518namespace {
1619
@@ -93,8 +96,8 @@ static bool parseNameValue(std::string_view line, std::string_view *name,
9396}
9497
9598// -----------------------------------------------------
96- DllExport void UkLoadKeyMap (FILE *f , int keyMap[256 ]) {
97- std::vector<UkKeyMapping> orderMap = UkLoadKeyOrderMap (f );
99+ DllExport void UkLoadKeyMap (int fd , int keyMap[256 ]) {
100+ std::vector<UkKeyMapping> orderMap = UkLoadKeyOrderMap (fd );
98101 initKeyMap (keyMap);
99102 for (const auto &item : orderMap) {
100103 keyMap[item.key ] = item.action ;
@@ -105,18 +108,19 @@ DllExport void UkLoadKeyMap(FILE *f, int keyMap[256]) {
105108}
106109
107110// ------------------------------------------------------------------
108- DllExport std::vector<UkKeyMapping> UkLoadKeyOrderMap (FILE *f ) {
111+ DllExport std::vector<UkKeyMapping> UkLoadKeyOrderMap (int fd ) {
109112 size_t lineCount = 0 ;
110113 int keyMap[256 ];
111114
112115 initKeyMap (keyMap);
113116
114117 std::vector<UkKeyMapping> pMap;
115- fcitx::UniqueCPtr<char > clineBuf;
116- size_t bufSize = 0 ;
117- while (getline (clineBuf, &bufSize, f) >= 0 ) {
118+ fcitx::IFDStreamBuf buf (fd);
119+ std::istream in (&buf);
120+ std::string line;
121+ while (std::getline (in, line)) {
118122 lineCount++;
119- auto text = fcitx::stringutils::trimView (clineBuf. get () );
123+ auto text = fcitx::stringutils::trimView (line );
120124 if (text.empty ()) {
121125 continue ;
122126 }
0 commit comments