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

Commit 6fd94600 authored by Greg Kaiser's avatar Greg Kaiser Committed by Automerger Merge Worker
Browse files

Merge "Revert "Remove unused String8::setPathName."" am: 615bf4ef am: 01f3306b am: 2cca5cc9

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

Change-Id: I9eb161676ecb73ba75d08b7d49b8305bf12455ab
parents 606ba34b 2cca5cc9
Loading
Loading
Loading
Loading
+14 −7
Original line number Original line Diff line number Diff line
@@ -431,17 +431,24 @@ void String8::toLower()
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// Path functions
// Path functions


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

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


    memcpy(buf, name, len);
    memcpy(buf, name, len);


    // remove trailing path separator, if present
    // 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';
    buf[len] = '\0';


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


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


@@ -574,7 +581,7 @@ String8& String8::appendPath(const char* name)


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