]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/strutl.cc
FileFd: avoid further writing if file failed
[apt.git] / apt-pkg / contrib / strutl.cc
index 60e3156f1f20efa24f4e3280fcbc32957284dcff..d388cbda3a4dd6f7f62f7ec13f9db391a82f075d 100644 (file)
@@ -464,7 +464,9 @@ string SubstVar(const string &Str,const string &Subst,const string &Contents)
 
    if (OldPos >= Str.length())
       return Temp;
-   return Temp + string(Str,OldPos);
+
+   Temp.append(Str, OldPos, string::npos);
+   return Temp;
 }
 string SubstVar(string Str,const struct SubstVar *Vars)
 {
@@ -788,7 +790,11 @@ bool ReadMessages(int Fd, vector<string> &List)
         return false;
 
       // No data
+#if EAGAIN != EWOULDBLOCK
       if (Res < 0 && (errno == EAGAIN || errno == EWOULDBLOCK))
+#else
+      if (Res < 0 && errno == EAGAIN)
+#endif
         return true;
       if (Res < 0)
         return false;
@@ -1113,13 +1119,18 @@ static int HexDigit(int c)
 // ---------------------------------------------------------------------
 /* The length of the buffer must be exactly 1/2 the length of the string. */
 bool Hex2Num(const string &Str,unsigned char *Num,unsigned int Length)
+{
+   return Hex2Num(APT::StringView(Str), Num, Length);
+}
+
+bool Hex2Num(const APT::StringView Str,unsigned char *Num,unsigned int Length)
 {
    if (Str.length() != Length*2)
       return false;
    
    // Convert each digit. We store it in the same order as the string
    int J = 0;
-   for (string::const_iterator I = Str.begin(); I != Str.end();J++, I += 2)
+   for (auto I = Str.begin(); I != Str.end();J++, I += 2)
    {
       int first_half = HexDigit(I[0]);
       int second_half;
@@ -1206,7 +1217,7 @@ vector<string> StringSplit(std::string const &s, std::string const &sep,
    vector<string> split;
    size_t start, pos;
 
-   // no seperator given, this is bogus
+   // no separator given, this is bogus
    if(sep.size() == 0)
       return split;
 
@@ -1377,6 +1388,7 @@ string StripEpoch(const string &VerStr)
    standard tolower/toupper and as a bonus avoids problems with different
    locales - we only operate on ascii chars anyway. */
 #undef tolower_ascii
+int tolower_ascii(int const c) APT_CONST APT_COLD;
 int tolower_ascii(int const c)
 {
    return tolower_ascii_inline(c);
@@ -1390,6 +1402,7 @@ int tolower_ascii(int const c)
    standard isspace() and as a bonus avoids problems with different
    locales - we only operate on ascii chars anyway. */
 #undef isspace_ascii
+int isspace_ascii(int const c) APT_CONST APT_COLD;
 int isspace_ascii(int const c)
 {
    return isspace_ascii_inline(c);