+ int fd = *(int *)handle;
+ AliasHandle h;
+ int id;
+ OSErr error;
+ Str255 pkey;
+
+ UseResFile(fd);
+ if (ResError() != noErr)
+ fatalbox("Failed to open saved session (%d)", ResError());
+
+ if (filename_is_null(fn)) {
+ /* Generate a special "null" alias */
+ h = (AliasHandle)NewHandle(sizeof(**h));
+ if (h == NULL)
+ fatalbox("Failed to create fake alias");
+ (*h)->userType = 'pTTY';
+ (*h)->aliasSize = sizeof(**h);
+ } else {
+ error = NewAlias(NULL, &fn.fss, &h);
+ if (error == fnfErr) {
+ /*
+ * NewAlias can't create an alias for a nonexistent file.
+ * Create an alias for the directory, and record the
+ * filename as well.
+ */
+ FSSpec tmpfss;
+
+ FSMakeFSSpec(fn.fss.vRefNum, fn.fss.parID, NULL, &tmpfss);
+ error = NewAlias(NULL, &tmpfss, &h);
+ if (error != noErr)
+ fatalbox("Failed to create alias");
+ (*h)->userType = 'pTTY';
+ SetHandleSize((Handle)h, (*h)->aliasSize + fn.fss.name[0] + 1);
+ if (MemError() != noErr)
+ fatalbox("Failed to create alias");
+ memcpy((char *)*h + (*h)->aliasSize, fn.fss.name,
+ fn.fss.name[0] + 1);
+ }
+ if (error != noErr)
+ fatalbox("Failed to create alias");
+ }
+ /* Put the data in a resource. */
+ id = Unique1ID(rAliasType);
+ if (ResError() != noErr)
+ fatalbox("Failed to get ID for resource %s (%d)", key, ResError());
+ c2pstrcpy(pkey, key);
+ AddResource((Handle)h, rAliasType, id, pkey);
+ if (ResError() != noErr)
+ fatalbox("Failed to add resource %s (%d)", key, ResError());