コード例 #1
0
ファイル: download.c プロジェクト: arczi84/NetSurf-68k
BOOL ami_download_check_overwrite(const char *file, struct Window *win, ULONG size)
{
	/* Return TRUE if file can be (over-)written */
	int32 res = 0;
	BPTR lock = 0;
	char *overwritetext;

	if(nsoption_bool(ask_overwrite) == false) return TRUE;

	lock = Lock(file, ACCESS_READ);

	if(lock)
	{
		if(size) {
			BPTR fh;
			int64 oldsize = 0;

			if((fh = OpenFromLock(lock))) {
				oldsize = GetFileSize(fh);
				Close(fh);
			}
			overwritetext = ASPrintf("%s\n\n%s %s\n%s %s",
				messages_get("OverwriteFile"),
				messages_get("amiSizeExisting"), human_friendly_bytesize((ULONG)oldsize),
				messages_get("amiSizeNew"), human_friendly_bytesize(size));
		} else {
			UnLock(lock);
			overwritetext = ASPrintf(messages_get("OverwriteFile"));
		}

		res = amiga_warn_user_multi(overwritetext, "Replace", "DontReplace", win);
		FreeVec(overwritetext);
	}
	else return TRUE;

	if(res == 1) return TRUE;
		else return FALSE;
}
コード例 #2
0
ファイル: amiga.c プロジェクト: yeonsh/Amoeba
/*
 * rpipe() - gets a `cmd' to run and a `file descriptor' to use as its stdin.
 */
int
rpipe(UBYTE * cmd, int fd)
{
    BPTR         fdFH = 0,	/* FileHandle of passed file descriptor */
                 outPH = 0,	/* Pipe (File) Handle for child to write to. */
                 inPH = 0,	/* Pipe (File) Handle for child to read from. */
                 lock = 0;
    int          fdr = 0;
    char         pname[32], *pc;
    extern char  o_shell[];

    if (isOldDOS())
	return -1;

    /*-
     * Sorry, I'm playing with an AZTEC internal here:
     * _devtab[fd].fd is Aztec's FileHandle for the file descriptor `fd'.
     * 
     * HINT: For your compiler, look in your compiler's fcntl.h.
     */

    switch (fd)
    {
    case 0:
	inPH = Open((UBYTE *) "*", MODE_READWRITE);
	break;
    default:

#ifdef	AZTEC_C
	fdFH = _devtab[fd].fd;		/* Grab FileHandle from fd */
#elif	_DCC
	fdFH = fdtofh(fd);		/* DCC does it right! */
#else
	return -1;			/* Sorry, can't help you. */
#endif

	/*
	 * Get a FileHandle to use for the child's stdin.
	 * The only reason we Dup is because we'll run the child ASynch,
	 * and it will close its Input and Output on exit.
	 */
	lock = DupLockFromFH(fdFH);
	if (!lock)
	    return -1;
	inPH = OpenFromLock(lock);
    }

    if (!inPH)
    {
	if (lock)
	    UnLock(lock);
	return -1;
    }

    /*
     * Get a pipe to use for the child's stdout, which we will read from.
     */
    strcpy(pname, "PIPE:ElvisXXX.XXX");
    pc = mktemp(pname);			/* Get a unique PIPE: */
    if (!*pc)
    {
    	Close(inPH);
	return -1;			/* Failure. */
    }

    /*
     * Get a FileHandle to use for the child's stdout.
     */
    if ((BPTR) 0 == (outPH = Open((UBYTE *) pc, MODE_NEWFILE)))
    {
	Close(inPH);
	return -1;			/* Failure. */
    }

    /* Get a file descriptor to return to the calling function */
    if ((fdr = open(pc, O_RDONLY)) < 0)
    {
	Close(inPH);
	Close(outPH);
	return -1;			/* Failure. */
    }

    /* exec the cmd */
    systags[0].ti_Data = inPH;		/* Input FileHandle for child */
    systags[1].ti_Data = outPH;		/* Output FileHandle for child */
    systags[2].ti_Data = (long) o_shell;/* which shell to use */

    if (System((UBYTE *) cmd, systags))
    {
	close(fdr);
	return -1;			/* Failure. */
    }

    return fdr;				/* Success! */
}