libsigrok
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines
binary.c
Go to the documentation of this file.
00001 /*
00002  * This file is part of the sigrok project.
00003  *
00004  * Copyright (C) 2010 Uwe Hermann <uwe@hermann-uwe.de>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00019  */
00020 
00021 #include <stdlib.h>
00022 #include <string.h>
00023 #include <glib.h>
00024 #include "sigrok.h"
00025 #include "sigrok-internal.h"
00026 
00027 static int data(struct sr_output *o, const uint8_t *data_in,
00028                 uint64_t length_in, uint8_t **data_out, uint64_t *length_out)
00029 {
00030         uint8_t *outbuf;
00031 
00032         /* Prevent compiler warnings. */
00033         (void)o;
00034 
00035         if (!data_in) {
00036                 sr_err("binary out: %s: data_in was NULL", __func__);
00037                 return SR_ERR_ARG;
00038         }
00039 
00040         if (!length_out) {
00041                 sr_err("binary out: %s: length_out was NULL", __func__);
00042                 return SR_ERR_ARG;
00043         }
00044 
00045         if (length_in == 0) {
00046                 sr_err("binary out: %s: length_in was 0", __func__);
00047                 return SR_ERR_ARG;
00048         }
00049 
00050         if (!(outbuf = g_try_malloc0(length_in))) {
00051                 sr_err("binary out: %s: outbuf malloc failed", __func__);
00052                 return SR_ERR_MALLOC;
00053         }
00054 
00055         memcpy(outbuf, data_in, length_in);
00056         *data_out = outbuf;
00057         *length_out = length_in;
00058 
00059         return SR_OK;
00060 }
00061 
00062 SR_PRIV struct sr_output_format output_binary = {
00063         .id = "binary",
00064         .description = "Raw binary",
00065         .df_type = SR_DF_LOGIC,
00066         .init = NULL,
00067         .data = data,
00068         .event = NULL,
00069 };
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines