Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 01f3306b authored by Greg Kaiser's avatar Greg Kaiser Committed by Automerger Merge Worker
Browse files

Merge "Revert "Remove unused String8::setPathName."" am: 615bf4ef

Original change: https://android-review.googlesource.com/c/platform/system/core/+/1768145

Change-Id: Ia4e7c9d015865964a87ab525c2c6f7105ea02b1f
parents eafdcd0b 615bf4ef
Loading
Loading
Loading
Loading
+14 −7
Original line number Diff line number Diff line
@@ -429,17 +429,24 @@ void String8::toLower()
// ---------------------------------------------------------------------------
// Path functions

static void setPathName(String8& s, const char* name) {
    size_t len = strlen(name);
    char* buf = s.lockBuffer(len);
void String8::setPathName(const char* name)
{
    setPathName(name, strlen(name));
}

void String8::setPathName(const char* name, size_t len)
{
    char* buf = lockBuffer(len);

    memcpy(buf, name, len);

    // remove trailing path separator, if present
    if (len > 0 && buf[len - 1] == OS_PATH_SEPARATOR) len--;
    if (len > 0 && buf[len-1] == OS_PATH_SEPARATOR)
        len--;

    buf[len] = '\0';

    s.unlockBuffer(len);
    unlockBuffer(len);
}

String8 String8::getPathLeaf(void) const
@@ -552,7 +559,7 @@ String8& String8::appendPath(const char* name)
        size_t len = length();
        if (len == 0) {
            // no existing filename, just use the new one
            setPathName(*this, name);
            setPathName(name);
            return *this;
        }

@@ -572,7 +579,7 @@ String8& String8::appendPath(const char* name)

        return *this;
    } else {
        setPathName(*this, name);
        setPathName(name);
        return *this;
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -89,6 +89,10 @@ std::vector<std::function<void(FuzzedDataProvider*, android::String8*, android::
                    str1->walkPath(path_out_str.get());
                    path_out_str->clear();
                },
                [](FuzzedDataProvider* dataProvider, android::String8* str1,
                   android::String8*) -> void {
                    str1->setPathName(dataProvider->ConsumeBytesWithTerminator<char>(5).data());
                },
                [](FuzzedDataProvider* dataProvider, android::String8* str1,
                   android::String8*) -> void {
                    str1->appendPath(dataProvider->ConsumeBytesWithTerminator<char>(5).data());
+8 −0
Original line number Diff line number Diff line
@@ -136,6 +136,14 @@ public:
     * These methods operate on the string as if it were a path name.
     */

    /*
     * Set the filename field to a specific value.
     *
     * Normalizes the filename, removing a trailing '/' if present.
     */
    void setPathName(const char* name);
    void setPathName(const char* name, size_t numChars);

    /*
     * Get just the filename component.
     *