{"id":238,"date":"2024-11-23T09:29:27","date_gmt":"2024-11-23T01:29:27","guid":{"rendered":"https:\/\/obagg.com\/index.php\/2024\/11\/23\/android-c-c-%e7%9f%a5%e8%af%86%e7%82%b9%e8%ae%b0%e5%bd%95\/"},"modified":"2024-11-23T09:29:27","modified_gmt":"2024-11-23T01:29:27","slug":"android-c-c-%e7%9f%a5%e8%af%86%e7%82%b9%e8%ae%b0%e5%bd%95","status":"publish","type":"post","link":"https:\/\/obagg.com\/index.php\/2024\/11\/23\/android-c-c-%e7%9f%a5%e8%af%86%e7%82%b9%e8%ae%b0%e5%bd%95\/","title":{"rendered":"Android C\/C++ \u77e5\u8bc6\u70b9\u8bb0\u5f55"},"content":{"rendered":"<h3>\u76ee\u5f55<\/h3>\n<ol>\n<li>ScopedUtfChars<\/li>\n<li>os.open() flags\u542b\u4e49<\/li>\n<\/ol>\n<h3>ScopedUtfChars<\/h3>\n<p>\u63d0\u4f9b\u5bf9 Java \u5b57\u7b26\u4e32\u7684 UTF \u5b57\u7b26\u7684\u53ea\u8bfb\u8bbf\u95ee\u7684\u667a\u80fd\u6307\u9488\u3002\u4e0e GetStringUTFChars \u4e0d\u540c\uff0c\u5982\u679c\u4f20\u9012\u4e00\u4e2a\u7a7a jstring\uff0c\u6211\u4eec\u5c06\u629b\u51fa NullPointerException \u800c\u4e0d\u662f\u4e2d\u6b62\uff0c\u5e76\u4e14 c_str \u5c06\u8fd4\u56de nullptr\u3002\u8fd9\u4f7f\u5f97\u6b63\u786e\u7684\u4e60\u60ef\u7528\u6cd5\u975e\u5e38\u7b80\u5355\uff1a<\/p>\n<pre><code>ScopedUtfChars name(env, java_name);\nif (name.c_str() == nullptr) {\n   return nullptr;\n}\n<\/code><\/pre>\n<p>\u793a\u4f8b\uff1a<\/p>\n<pre><code>static bool dumpTraces(JNIEnv* env, jint pid, jstring fileName, jint timeoutSecs,\n                       DebuggerdDumpType dumpType) {\n    const ScopedUtfChars fileNameChars(env, fileName);\n    if (fileNameChars.c_str() == nullptr) {\n        return false;\n    }\n    ...\n}\n<\/code><\/pre>\n<p>\u6e90\u7801\uff1a<\/p>\n<pre><code>  ScopedUtfChars(JNIEnv* env, jstring s) : env_(env), string_(s) {\n    if (s == nullptr) {\n      utf_chars_ = nullptr;\n      jniThrowNullPointerException(env, nullptr);\n    } else {\n      utf_chars_ = env-&gt;GetStringUTFChars(s, nullptr);\n    }\n  }\n<\/code><\/pre>\n<h3>os.open() flags\u542b\u4e49<\/h3>\n<ul>\n<li>os.O_RDONLY: \u4ee5\u53ea\u8bfb\u7684\u65b9\u5f0f\u6253\u5f00<\/li>\n<li>os.O_WRONLY: \u4ee5\u53ea\u5199\u7684\u65b9\u5f0f\u6253\u5f00<\/li>\n<li>os.O_RDWR : \u4ee5\u8bfb\u5199\u7684\u65b9\u5f0f\u6253\u5f00<\/li>\n<li>os.O_NONBLOCK: \u6253\u5f00\u65f6\u4e0d\u963b\u585e<\/li>\n<li>os.O_APPEND: \u4ee5\u8ffd\u52a0\u7684\u65b9\u5f0f\u6253\u5f00<\/li>\n<li>os.O_CREAT: \u521b\u5efa\u5e76\u6253\u5f00\u4e00\u4e2a\u65b0\u6587\u4ef6<\/li>\n<li>os.O_TRUNC: \u6253\u5f00\u4e00\u4e2a\u6587\u4ef6\u5e76\u622a\u65ad\u5b83\u7684\u957f\u5ea6\u4e3a\u96f6\uff08\u5fc5\u987b\u6709\u5199\u6743\u9650\uff09<\/li>\n<li>os.O_EXCL: \u5982\u679c\u6307\u5b9a\u7684\u6587\u4ef6\u5b58\u5728\uff0c\u8fd4\u56de\u9519\u8bef<\/li>\n<li>os.O_SHLOCK: \u81ea\u52a8\u83b7\u53d6\u5171\u4eab\u9501<\/li>\n<li>os.O_EXLOCK: \u81ea\u52a8\u83b7\u53d6\u72ec\u7acb\u9501<\/li>\n<li>os.O_DIRECT: \u6d88\u9664\u6216\u51cf\u5c11\u7f13\u5b58\u6548\u679c<\/li>\n<li>os.O_FSYNC : \u540c\u6b65\u5199\u5165<\/li>\n<li>os.O_NOFOLLOW: \u4e0d\u8ffd\u8e2a\u8f6f\u94fe\u63a5<\/li>\n<li>os.O_CLOEXEC: \u5f53\u8c03\u7528exec\u6210\u529f\u540e\uff0c\u6587\u4ef6\u4f1a\u81ea\u52a8\u5173\u95ed<\/li>\n<\/ul>\n<p>Please credit: <a href=\"https:\/\/obagg.com\">OBA Blog<\/a> &raquo; <a href=\"https:\/\/obagg.com\/index.php\/2024\/11\/23\/android-c-c-%e7%9f%a5%e8%af%86%e7%82%b9%e8%ae%b0%e5%bd%95\/\">Android C\/C++ \u77e5\u8bc6\u70b9\u8bb0\u5f55<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55 ScopedUtfChars os.open() flags\u542b\u4e49 ScopedUtfChars \u63d0\u4f9b\u5bf9 Java \u5b57\u7b26\u4e32\u7684 UTF \u5b57\u7b26\u7684\u53ea\u8bfb\u8bbf\u95ee\u7684\u667a\u80fd\u6307\u9488\u3002\u4e0e GetStringUTFChars \u4e0d\u540c\uff0c\u5982\u679c\u4f20\u9012\u4e00\u4e2a\u7a7a jstring\uff0c\u6211\u4eec\u5c06\u629b\u51fa NullPointerException \u800c\u4e0d\u662f\u4e2d\u6b62\uff0c\u5e76\u4e14 c_str \u5c06\u8fd4\u56de nullptr\u3002\u8fd9\u4f7f\u5f97\u6b63\u786e\u7684\u4e60\u60ef\u7528\u6cd5\u975e\u5e38\u7b80\u5355\uff1a ScopedUtfChars name(env, java_name); if (name.c_str() == nullptr) { return nullptr; } \u793a\u4f8b\uff1a static bool dumpTraces(JNIEnv* env, jint pid, jstring fileName, jint timeoutSecs, DebuggerdDumpType dumpType) { const ScopedUtfChars fileNameChars(env, fileName); if (fileNameChars.c_str() == nullptr) { return false; } &#8230; } \u6e90\u7801\uff1a ScopedUtfChars(JNIEnv* env, jstring s) : env_(env), string_(s) { if (s == nullptr) { utf_chars_ = nullptr; jniThrowNullPointerException(env, nullptr); } else { utf_chars_ = env-&gt;GetStringUTFChars(s, nullptr); } } os.open() flags\u542b\u4e49 os.O_RDONLY: \u4ee5\u53ea\u8bfb\u7684\u65b9\u5f0f\u6253\u5f00 os.O_WRONLY: \u4ee5\u53ea\u5199\u7684\u65b9\u5f0f\u6253\u5f00 os.O_RDWR : \u4ee5\u8bfb\u5199\u7684\u65b9\u5f0f\u6253\u5f00 os.O_NONBLOCK: \u6253\u5f00\u65f6\u4e0d\u963b\u585e os.O_APPEND: \u4ee5\u8ffd\u52a0\u7684\u65b9\u5f0f\u6253\u5f00 os.O_CREAT: \u521b\u5efa\u5e76\u6253\u5f00\u4e00\u4e2a\u65b0\u6587\u4ef6 os.O_TRUNC: \u6253\u5f00\u4e00\u4e2a\u6587\u4ef6\u5e76\u622a\u65ad\u5b83\u7684\u957f\u5ea6\u4e3a\u96f6\uff08\u5fc5\u987b\u6709\u5199\u6743\u9650\uff09 os.O_EXCL: \u5982\u679c\u6307\u5b9a\u7684\u6587\u4ef6\u5b58\u5728\uff0c\u8fd4\u56de\u9519\u8bef os.O_SHLOCK: \u81ea\u52a8\u83b7\u53d6\u5171\u4eab\u9501 os.O_EXLOCK: \u81ea\u52a8\u83b7\u53d6\u72ec\u7acb\u9501 os.O_DIRECT: \u6d88\u9664\u6216\u51cf\u5c11\u7f13\u5b58\u6548\u679c os.O_FSYNC : \u540c\u6b65\u5199\u5165 os.O_NOFOLLOW: \u4e0d\u8ffd\u8e2a\u8f6f\u94fe\u63a5 os.O_CLOEXEC: \u5f53\u8c03\u7528exec\u6210\u529f\u540e\uff0c\u6587\u4ef6\u4f1a\u81ea\u52a8\u5173\u95ed Please credit: OBA Blog &raquo; Android C\/C++ \u77e5\u8bc6\u70b9\u8bb0\u5f55<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-238","post","type-post","status-publish","format-standard","hentry","category-share"],"_links":{"self":[{"href":"https:\/\/obagg.com\/index.php\/wp-json\/wp\/v2\/posts\/238","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/obagg.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/obagg.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/obagg.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/obagg.com\/index.php\/wp-json\/wp\/v2\/comments?post=238"}],"version-history":[{"count":0,"href":"https:\/\/obagg.com\/index.php\/wp-json\/wp\/v2\/posts\/238\/revisions"}],"wp:attachment":[{"href":"https:\/\/obagg.com\/index.php\/wp-json\/wp\/v2\/media?parent=238"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/obagg.com\/index.php\/wp-json\/wp\/v2\/categories?post=238"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/obagg.com\/index.php\/wp-json\/wp\/v2\/tags?post=238"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}