/* Copyright 1996 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/* File:    rmensure.c
 * Purpose: ensuring a module is loaded
 * Author:  IDJ
 * History: 24-Jun-94: IDJ: created
 *          02-Dec-96: KJB: modified ROM conditional - RAM modules still need
 *                          to use rmensure in TinyStubs
 */


#include <stdio.h>
#include "kernel.h"
#include "swis.h"

#include "rmensure.h"
#include "macros.h"

_kernel_oserror *rmensure (char *module_name, char *file_name, char *module_version)
{
#if defined(ROM) && !defined(BUILDING_TINYSTUBS)
    IGNORE(module_area);
    IGNORE(file_name);
    IGNORE(module_version);

    return NULL;
#else
    _kernel_oserror *e;
    char command[256];

    /*
     * see if the module is there at all!
     */

    sprintf (command, "RMEnsure %s %s RMLoad System:Modules.%s", module_name,
                                module_version, file_name);

    if ((e = _swix (OS_CLI, _IN(0), command)) != NULL)
        return e;

    sprintf (command, "RMEnsure %s %s", module_name, module_version);

    return _swix (OS_CLI, _IN(0), command);
#endif
}