/*
    (C) 1995-96 AROS - The Amiga Replacement OS
    $Id: getdiskobject.c,v 1.3 1997/03/27 15:36:41 digulla Exp $

    Desc:
    Lang: english
*/
#include <proto/arossupport.h>
#include <proto/dos.h>
#include "icon_intern.h"

extern const IPTR IconDesc[];

/*****************************************************************************

    NAME */
#include <clib/icon_protos.h>

	AROS_LH1(struct DiskObject *, GetDiskObject,

/*  SYNOPSIS */
	AROS_LHA(UBYTE *, name, A0),

/*  LOCATION */
	struct Library *, IconBase, 13, Icon)

/*  FUNCTION

    INPUTS

    RESULT

    NOTES

    EXAMPLE

    BUGS

    SEE ALSO

    INTERNALS

    HISTORY

*****************************************************************************/
{
    AROS_LIBFUNC_INIT
    AROS_LIBBASE_EXT_DECL(struct Library *,IconBase)
    struct DiskObject * dobj;
    char * iconname;
    BPTR   icon;

    /* Name with correct extension ? */
    if (strrncasecmp (name, ".info", 5))
    {
	/* Create the final filename */
	if (!(iconname = AllocVec (strlen (name) + 5 + 1, MEMF_ANY)) )
	    return NULL;

	strcpy (iconname, name);
	strcat (iconname, ".info");

	/* Try to open that file */
	icon = Open (iconname, MODE_OLDFILE);

	FreeVec (iconname);
    }
    else
	icon = Open (name, MODE_OLDFILE);

    if (!icon)
	return NULL;

    /* Read the file in */
    if (!ReadStruct (&LB(IconBase)->dsh, (APTR *)&dobj, icon, IconDesc))
	dobj = NULL;

    Close (icon);

    return dobj;
    AROS_LIBFUNC_EXIT
} /* GetDiskObject */
