+/* -------------------- */
+static int ad_mkrf(char *path)
+{
+ char *slash;
+ /*
+ * Probably .AppleDouble doesn't exist, try to mkdir it.
+ */
+ if (NULL == ( slash = strrchr( path, '/' )) ) {
+ return -1;
+ }
+ *slash = '\0';
+ errno = 0;
+ if ( ad_mkdir( path, 0777 ) < 0 ) {
+ return -1;
+ }
+ *slash = '/';
+ return 0;
+}
+
+/* ---------------------------------------
+ * Put the resource fork where it needs to be:
+ * ._name
+ */
+char *
+ad_path_osx(const char *path, int adflags _U_)
+{
+ static char pathbuf[ MAXPATHLEN + 1];
+ char c, *slash, buf[MAXPATHLEN + 1];
+
+ if (!strcmp(path,".")) {
+ /* fixme */
+ getcwd(buf, MAXPATHLEN);
+ }
+ else {
+ strlcpy(buf, path, MAXPATHLEN +1);
+ }
+ if (NULL != ( slash = strrchr( buf, '/' )) ) {
+ c = *++slash;
+ *slash = '\0';
+ strlcpy( pathbuf, buf, MAXPATHLEN +1);
+ *slash = c;
+ } else {
+ pathbuf[ 0 ] = '\0';
+ slash = buf;
+ }
+ strlcat( pathbuf, "._", MAXPATHLEN +1);
+ strlcat( pathbuf, slash, MAXPATHLEN +1);
+ return pathbuf;
+}
+/* -------------------- */
+static int ad_mkrf_osx(char *path _U_)
+{
+ return 0;
+}
+
+/* ---------------------------------------
+ * Put the .AppleDouble where it needs to be:
+ *
+ * / a/.AppleDouble/b/Afp_AfpInfo
+ * a/b
+ * \ b/.AppleDouble/.Parent/Afp_AfpInfo
+ *
+ */
+char *
+ad_path_ads( path, adflags )
+ const char *path;
+ int adflags;
+{
+ static char pathbuf[ MAXPATHLEN + 1];
+ char c, *slash, buf[MAXPATHLEN + 1];
+ size_t l;
+
+ l = strlcpy(buf, path, MAXPATHLEN +1);
+ if ( adflags & ADFLAGS_DIR ) {
+ strcpy( pathbuf, buf);
+ if ( *buf != '\0' && l < MAXPATHLEN) {
+ pathbuf[l++] = '/';
+ pathbuf[l] = 0;
+ }
+ slash = ".Parent";
+ } else {
+ if (NULL != ( slash = strrchr( buf, '/' )) ) {
+ c = *++slash;
+ *slash = '\0';
+ strcpy( pathbuf, buf);
+ *slash = c;
+ } else {
+ pathbuf[ 0 ] = '\0';
+ slash = buf;
+ }
+ }
+ strlcat( pathbuf, ".AppleDouble/", MAXPATHLEN +1);
+ strlcat( pathbuf, slash, MAXPATHLEN +1);
+
+ strlcat( pathbuf, "/Afp_AfpInfo", MAXPATHLEN +1);
+ return( pathbuf );
+}
+
+/* ----------------------
+ * mostly the same as ads, only case change Afp --> AFP and AFP_Resoure
+*/
+char *
+ad_path_sfm( path, adflags )
+ const char *path;
+ int adflags;
+{
+ static char pathbuf[ MAXPATHLEN + 1];
+ char c, *slash, buf[MAXPATHLEN + 1];
+ size_t l;
+
+ l = strlcpy(buf, path, MAXPATHLEN +1);
+ if ( adflags & ADFLAGS_DIR ) {
+ strcpy( pathbuf, buf);
+ if ( *buf != '\0' && l < MAXPATHLEN) {
+ pathbuf[l++] = '/';
+ pathbuf[l] = 0;
+ }
+ slash = ".Parent";
+ } else {
+ if (NULL != ( slash = strrchr( buf, '/' )) ) {
+ c = *++slash;
+ *slash = '\0';
+ strcpy( pathbuf, buf);
+ *slash = c;
+ } else {
+ pathbuf[ 0 ] = '\0';
+ slash = buf;
+ }
+ }
+ strlcat( pathbuf, ".AppleDouble/", MAXPATHLEN +1);
+ strlcat( pathbuf, slash, MAXPATHLEN +1);
+
+ if ((adflags == ADFLAGS_RF)) {
+ strlcat( pathbuf, "/AFP_Resource", MAXPATHLEN +1);
+ }
+ else {
+ strlcat( pathbuf, "/AFP_AfpInfo", MAXPATHLEN +1);
+ }
+ return( pathbuf );
+}
+
+/* -------------------- */
+static int ad_mkrf_ads(char *path)
+{
+ char *slash;
+ /*
+ * Probably .AppleDouble doesn't exist, try to mkdir it.
+ */
+ if (NULL == ( slash = strrchr( path, '/' )) ) {
+ return -1;
+ }
+ *slash = 0;
+ errno = 0;
+ if ( ad_mkdir( path, 0777 ) < 0 ) {
+ if ( errno == ENOENT ) {
+ char *slash1;
+
+ if (NULL == ( slash1 = strrchr( path, '/' )) )
+ return -1;
+ errno = 0;
+ *slash1 = 0;
+ if ( ad_mkdir( path, 0777 ) < 0 )
+ return -1;
+ *slash1 = '/';
+ if ( ad_mkdir( path, 0777 ) < 0 )
+ return -1;
+ }
+ else
+ return -1;
+ }
+ *slash = '/';
+ return 0;
+}
+
+/* -------------------------