⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的动态下载程序源码。
💻 C
字号:
/*
 * Copyright (c) 1995,2000 TriMedia Technologies Inc.           
 *
 * +------------------------------------------------------------------+
 * | This software is furnished under a license and may only be used  |
 * | and copied in accordance with the terms and conditions of  such  |
 * | a license and with the inclusion of this copyright notice. This  |
 * | software or any other copies of this software may not be provided|
 * | or otherwise made available to any other person.  The ownership  |
 * | and title of this software is not transferred.                   |
 * |                                                                  |
 * | The information in this software is subject  to change without   |
 * | any  prior notice and should not be construed as a commitment by |
 * | TriMedia Technologies.                                           |
 * |                                                                  |
 * | this code and information is provided "as is" without any        |
 * | warranty of any kind, either expressed or implied, including but |
 * | not limited to the implied warranties of merchantability and/or  |
 * | fitness for any particular purpose.                              |
 * +------------------------------------------------------------------+
 *
 *  Module name              : main.c    1.4
 *
 *  Last update              : 11:22:05 - 00/06/19
 *
 *  Description              : Simple dynamic library upgrading example.
 *                             This example uses a particular lib,
 *                             unloads it, and then loads an upgraded
 *                             version and uses it again.
 *
 */

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <fcntl.h>
#include "tmlib/DynamicLoader.h"


static void copy_file(String new, String old) 
{
    Int          fd,gd;
    struct stat  info;
    Pointer      buffer;

    stat(new, &info);

    buffer= (Pointer)malloc(info.st_size);

    fd= open(new, O_RDONLY | O_BINARY );
    gd= open(old, O_WRONLY | O_BINARY | O_CREAT );

    read (fd, buffer, info.st_size );
    write(gd, buffer, info.st_size );

    close(fd);
    close(gd);

    free(buffer);
}



/*
 * external interface of 'the lib'
 */
extern char * version();
extern int square(int x);


/*
 * use the currently installed library;
 * it will be loaded upon the first call
 * to function 'square`:
 */
static void use_the_lib()
{
    int i;

    for (i=0; i<10; i++) {
        printf(" square(%d)= %d\n", i, square(i) );
    }
}


/*
 * unload the library from memory
 * (when present). This is only
 * possible when it has no current users:
 */
static int unload_the_lib(String lib) 
{
    switch (DynLoad_unload_dll(lib)) {

    case DynLoad_OK:
    case DynLoad_NotPresent:
            return 0;

    case DynLoad_NotUnloadable:
    case DynLoad_StillReferenced:
            return -1;
    }
}




void main()
{
   /*
    * Start using the library; this will result
    * in implicit loading of the thing (because it
    * was linked in deferred mode):
    */
    use_the_lib();

    printf("Library version: '%s'\n", version());  


   /*
    * Simulate an update of the library (just a
    * file copy here), and unload its old version
    * from memory:
    */
    copy_file("lib_new.dll", "lib.dll");

    unload_the_lib("lib.dll");


   /*
    * Continue using the library; this will again
    * result in implicit loading of the library:
    */
    use_the_lib();

    printf("Library version: '%s'\n", version());  


   /*
    * Restore the original state, 
    * so that this program can be rerun:
    */
    copy_file("lib_old.dll", "lib.dll");

    exit(0);
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -