- } else {
- /* start_offset_percent not set */
- offset = o->start_offset +
- td->subjob_number * o->offset_increment;
+ return offset;
+}
+
+/*
+ * Find longest path component that exists and return its length
+ */
+int longest_existing_path(char *path) {
+ char buf[PATH_MAX];
+ bool done;
+ char *buf_pos;
+ int offset;
+#ifdef WIN32
+ DWORD dwAttr;
+#else
+ struct stat sb;
+#endif
+
+ sprintf(buf, "%s", path);
+ done = false;
+ while (!done) {
+ buf_pos = strrchr(buf, FIO_OS_PATH_SEPARATOR);
+ if (!buf_pos) {
+ done = true;
+ offset = 0;
+ break;
+ }
+
+ *(buf_pos + 1) = '\0';
+
+#ifdef WIN32
+ dwAttr = GetFileAttributesA(buf);
+ if (dwAttr != INVALID_FILE_ATTRIBUTES) {
+ done = true;
+ }
+#else
+ if (stat(buf, &sb) == 0)
+ done = true;
+#endif
+ if (done)
+ offset = buf_pos - buf;
+ else
+ *buf_pos = '\0';