Beispiel #1
0
int send_fcgi_buffer(t_fcgi_buffer *fcgi_buffer, const char *buffer, int size) {
/*    int padding;*/

    if (size > FCGI_BUFFER_SIZE) {
        if (fcgi_buffer->size > 0) {
            set_padding(fcgi_buffer, true);
            if (send_directly(fcgi_buffer->sock, (char*)fcgi_buffer->data, fcgi_buffer->size) == -1) {
                return -1;
            }
        }

        memcpy(fcgi_buffer->data, "\x01\x00\x00\x01" "\xff\xff\x00\x00", 8);
        fcgi_buffer->data[1] = fcgi_buffer->mode;
        fcgi_buffer->data[4] = (FCGI_BUFFER_SIZE >> 8 ) & 255;
        fcgi_buffer->data[5] = FCGI_BUFFER_SIZE & 255;

        int padding = set_padding(fcgi_buffer, false);
        if (send_directly(fcgi_buffer->sock, (char*)fcgi_buffer->data, 8) == -1) {
            return -1;
        } else if (send_directly(fcgi_buffer->sock, buffer, FCGI_BUFFER_SIZE) == -1) {
            return -1;
        }

        fcgi_buffer->size = 0;
        memset(fcgi_buffer->data, 0, (size_t)padding);

        if (send_directly(fcgi_buffer->sock, (char*)fcgi_buffer->data, padding) == -1) {
            return -1;
        } else if (send_fcgi_buffer(fcgi_buffer, buffer + FCGI_BUFFER_SIZE, size - FCGI_BUFFER_SIZE) == -1) {
            return -1;
        }
    } else if (buffer == NULL) {
static gboolean
set_ypad (GtkSourceGutter *gutter,
          gint             ypad,
          gboolean         resize)
{
	return set_padding (gutter, &gutter->priv->ypad, ypad, "ypad", resize);
}
static gboolean
set_xpad (GtkSourceGutter *gutter,
          gint             xpad,
          gboolean         resize)
{
	return set_padding (gutter, &gutter->priv->xpad, xpad, "xpad", resize);
}
static gboolean
set_ypad (GtkSourceGutterRenderer *renderer,
          gint                     ypad)
{
	return set_padding (renderer,
	                    &renderer->priv->ypad,
	                    ypad,
	                    "ypad");
}
static gboolean
set_xpad (GtkSourceGutterRenderer *renderer,
          gint                     xpad)
{
	return set_padding (renderer,
	                    &renderer->priv->xpad,
	                    xpad,
	                    "xpad");
}
Beispiel #6
0
static void
gltk_spinner_set_property(GObject* object, guint property_id, const GValue* value, GParamSpec* pspec)
{
    GltkSpinner* self = GLTK_SPINNER(object);
    USING_PRIVATE(self);

    switch (property_id)
    {
    case PROP_MODEL:
    {
        GltkSpinnerModel* model = GLTK_SPINNER_MODEL(g_value_get_object(value));
        priv->hbox = gltk_hbox_new(1);

        g_object_ref(model);
        priv->model = model;

        //initialize the wheels
        priv->wheels = g_new(Wheel, priv->model->levels);
        int i;
        for (i = 0; i < priv->model->levels; i++)
        {
            Wheel* wheel = priv->wheels + i;

            wheel->vbox = gltk_vbox_new(0);
            wheel->scrollable = gltk_scrollable_new();
            g_object_ref(wheel->vbox);
            g_object_ref(wheel->scrollable);
            gltk_scrollable_set_widget(GLTK_SCROLLABLE(wheel->scrollable), wheel->vbox);
            gltk_box_append_widget(GLTK_BOX(priv->hbox), wheel->scrollable, TRUE, TRUE);

            g_signal_connect(wheel->scrollable, "touch-event", (GCallback)scrollable_touch_event, self);

            wheel->items = NULL;
            wheel->index = 0;
        }

        //load our toplevel items from the model
        load_items(self, 0, gltk_spinner_model_clone_items(priv->model, priv->model->toplevel));

        gltk_bin_set_widget(GLTK_BIN(self), priv->hbox);
    }
    break;
    case PROP_VISIBLE_ITEMS:
    {
        priv->visibleItems = g_value_get_int(value);
        int i;
        for (i = 0; i < priv->model->levels; i++)
            set_padding(self, &priv->wheels[i]);
        gltk_widget_layout(GLTK_WIDGET(object));
    }
    break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
    }
}
Beispiel #7
0
void BoxStyle::set_padding(float size)
{
    set_padding(size, size, size, size);
}
Beispiel #8
0
void BoxStyle::set_padding(float width, float height)
{
    set_padding(width, height, width, height);
}
Beispiel #9
0
static BOOL TestPrimitiveYUV(BOOL use444)
{
	BOOL rc = FALSE;
	UINT32 x, y;
	UINT32 awidth, aheight;
	BYTE* yuv[3] = {0};
	UINT32 yuv_step[3];
	prim_size_t roi;
	BYTE* rgb = NULL;
	BYTE* rgb_dst = NULL;
	size_t size;
	primitives_t* prims = primitives_get();
	size_t uvsize, uvwidth;
	size_t padding = 10000;
	size_t stride;
	get_size(&roi.width, &roi.height);
	/* Buffers need to be 16x16 aligned. */
	awidth = roi.width + 16 - roi.width % 16;
	aheight = roi.height + 16 - roi.height % 16;
	stride = awidth * sizeof(UINT32);
	size = awidth * aheight;

	if (use444)
	{
		uvwidth = awidth;
		uvsize = size;

		if (!prims || !prims->RGBToYUV444_8u_P3AC4R || !prims->YUV444ToRGB_8u_P3AC4R)
			return FALSE;
	}
	else
	{
		uvwidth = (awidth + 1) / 2;
		uvsize = (aheight + 1) / 2 * uvwidth;

		if (!prims || !prims->RGBToYUV420_8u_P3AC4R || !prims->YUV420ToRGB_8u_P3AC4R)
			return FALSE;
	}

	fprintf(stderr, "Running AVC%s on frame size %"PRIu32"x%"PRIu32"\n", use444 ? "444" : "420",
		roi.width, roi.height);

	/* Test RGB to YUV444 conversion and vice versa */
	if (!(rgb = set_padding(size * sizeof(UINT32), padding)))
		goto fail;

	if (!(rgb_dst = set_padding(size * sizeof(UINT32), padding)))
		goto fail;

	if (!(yuv[0] = set_padding(size, padding)))
		goto fail;

	if (!(yuv[1] = set_padding(uvsize, padding)))
		goto fail;

	if (!(yuv[2] = set_padding(uvsize, padding)))
		goto fail;

	for (y = 0; y < roi.height; y++)
	{
		BYTE* line = &rgb[y * stride];

		for (x = 0; x < roi.width; x++)
		{
			line[x * 4 + 0] = 0x81;
			line[x * 4 + 1] = 0x33;
			line[x * 4 + 2] = 0xAB;
			line[x * 4 + 3] = 0xFF;
		}
	}

	yuv_step[0] = awidth;
	yuv_step[1] = uvwidth;
	yuv_step[2] = uvwidth;

	if (use444)
	{
		if (prims->RGBToYUV444_8u_P3AC4R(rgb, PIXEL_FORMAT_BGRA32,
						 stride, yuv, yuv_step,
						 &roi) != PRIMITIVES_SUCCESS)
			goto fail;
	}
	else if (prims->RGBToYUV420_8u_P3AC4R(rgb, PIXEL_FORMAT_BGRA32,
					      stride, yuv, yuv_step,
					      &roi) != PRIMITIVES_SUCCESS)
		goto fail;

	if (!check_padding(rgb, size * sizeof(UINT32), padding, "rgb"))
		goto fail;

	if ((!check_padding(yuv[0], size, padding, "Y")) ||
	    (!check_padding(yuv[1], uvsize, padding, "U")) ||
	    (!check_padding(yuv[2], uvsize, padding, "V")))
		goto fail;

	if (use444)
	{
		if (prims->YUV444ToRGB_8u_P3AC4R((const BYTE**)yuv, yuv_step, rgb_dst, stride,
						 PIXEL_FORMAT_BGRA32,
						 &roi) != PRIMITIVES_SUCCESS)
			goto fail;
	}
	else if (prims->YUV420ToRGB_8u_P3AC4R((const BYTE**)yuv, yuv_step, rgb_dst,
					      stride, PIXEL_FORMAT_BGRA32, &roi) != PRIMITIVES_SUCCESS)
		goto fail;

	if (!check_padding(rgb_dst, size * sizeof(UINT32), padding, "rgb dst"))
		goto fail;

	if ((!check_padding(yuv[0], size, padding, "Y")) ||
	    (!check_padding(yuv[1], uvsize, padding, "U")) ||
	    (!check_padding(yuv[2], uvsize, padding, "V")))
		goto fail;

	for (y = 0; y < roi.height; y++)
	{
		BYTE* srgb = &rgb[y * stride];
		BYTE* drgb = &rgb_dst[y * stride];

		if (!similar(srgb, drgb, roi.width * sizeof(UINT32)))
			goto fail;
	}

	rc = TRUE;
fail:
	free_padding(rgb, padding);
	free_padding(rgb_dst, padding);
	free_padding(yuv[0], padding);
	free_padding(yuv[1], padding);
	free_padding(yuv[2], padding);
	return rc;
}
Beispiel #10
0
/* Create 2 pseudo YUV420 frames of same size.
 * Combine them and check, if the data is at the expected position. */
static BOOL TestPrimitiveYUVCombine(void)
{
	UINT32 x, y, i;
	UINT32 awidth, aheight;
	BOOL rc = FALSE;
	BYTE* luma[3] = { 0 };
	BYTE* chroma[3] = { 0 };
	BYTE* yuv[3] = { 0 };
	BYTE* pmain[3] = { 0 };
	BYTE* paux[3] = { 0 };
	UINT32 lumaStride[3];
	UINT32 chromaStride[3];
	UINT32 yuvStride[3];
	size_t padding = 10000;
	prim_size_t roi;
	primitives_t* prims = primitives_get();
	get_size(&roi.width, &roi.height);
	awidth = roi.width + 16 - roi.width % 16;
	aheight = roi.height + 16 - roi.height % 16;
	fprintf(stderr, "Running YUVCombine on frame size %"PRIu32"x%"PRIu32" [%"PRIu32"x%"PRIu32"]\n",
		roi.width, roi.height, awidth, aheight);

	if (!prims || !prims->YUV420CombineToYUV444)
		goto fail;

	for (x = 0; x < 3; x++)
	{
		size_t halfStride = ((x > 0) ? awidth / 2 : awidth);
		size_t size = aheight * awidth;
		size_t halfSize = ((x > 0) ? halfStride * aheight / 2 : awidth * aheight);
		yuvStride[x] = awidth;

		if (!(yuv[x] = set_padding(size, padding)))
			goto fail;

		lumaStride[x] = halfStride;

		if (!(luma[x] = set_padding(halfSize, padding)))
			goto fail;

		if (!(pmain[x] = set_padding(halfSize, padding)))
			goto fail;

		chromaStride[x] = halfStride;

		if (!(chroma[x] = set_padding(halfSize, padding)))
			goto fail;

		if (!(paux[x] = set_padding(halfSize, padding)))
			goto fail;

		memset(luma[x], 0xAB + 3 * x, halfSize);
		memset(chroma[x], 0x80 + 2 * x, halfSize);

		if (!check_padding(luma[x], halfSize, padding, "luma"))
			goto fail;

		if (!check_padding(chroma[x], halfSize, padding, "chroma"))
			goto fail;

		if (!check_padding(pmain[x], halfSize, padding, "main"))
			goto fail;

		if (!check_padding(paux[x], halfSize, padding, "aux"))
			goto fail;

		if (!check_padding(yuv[x], size, padding, "yuv"))
			goto fail;
	}

	if (prims->YUV420CombineToYUV444((const BYTE**)luma, lumaStride,
					 (const BYTE**)chroma, chromaStride,
					 yuv, yuvStride, &roi) != PRIMITIVES_SUCCESS)
		goto fail;

	for (x = 0; x < 3; x++)
	{
		size_t halfStride = ((x > 0) ? awidth / 2 : awidth);
		size_t size = aheight * awidth;
		size_t halfSize = ((x > 0) ? halfStride * aheight / 2 : awidth * aheight);

		if (!check_padding(luma[x], halfSize, padding, "luma"))
			goto fail;

		if (!check_padding(chroma[x], halfSize, padding, "chroma"))
			goto fail;

		if (!check_padding(yuv[x], size, padding, "yuv"))
			goto fail;
	}

	if (prims->YUV444SplitToYUV420((const BYTE**)yuv, yuvStride, pmain, lumaStride,
				       paux, chromaStride, &roi) != PRIMITIVES_SUCCESS)
		goto fail;

	for (x = 0; x < 3; x++)
	{
		size_t halfStride = ((x > 0) ? awidth / 2 : awidth);
		size_t size = aheight * awidth;
		size_t halfSize = ((x > 0) ? halfStride * aheight / 2 : awidth * aheight);

		if (!check_padding(pmain[x], halfSize, padding, "main"))
			goto fail;

		if (!check_padding(paux[x], halfSize, padding, "aux"))
			goto fail;

		if (!check_padding(yuv[x], size, padding, "yuv"))
			goto fail;
	}

	for (i = 0; i < 3; i++)
	{
		for (y = 0; y < roi.height; y++)
		{
			UINT32 w = roi.width;
			UINT32 lstride = lumaStride[i];
			UINT32 cstride = chromaStride[i];

			if (i > 0)
			{
				w = (roi.width + 3) / 4;

				if (roi.height > (roi.height + 1) / 2)
					continue;
			}

			if (!similar(luma[i] + y * lstride,
				     pmain[i]  + y * lstride,
				     w))
				goto fail;

			/* Need to ignore lines of destination Y plane,
			 * if the lines are not a multiple of 16
			 * as the UV planes are packed in 8 line stripes. */
			if (i == 0)
			{
				/* TODO: This check is not perfect, it does not
				 * include the last V lines packed to the Y
				 * frame. */
				UINT32 rem = roi.height % 16;

				if (y > roi.height - rem)
					continue;
			}

			if (!similar(chroma[i] + y * cstride,
				     paux[i]  + y * cstride,
				     w))
				goto fail;
		}
	}

	rc = TRUE;
fail:

	for (x = 0; x < 3; x++)
	{
		free_padding(yuv[x], padding);
		free_padding(luma[x], padding);
		free_padding(chroma[x], padding);
		free_padding(pmain[x], padding);
		free_padding(paux[x], padding);
	}

	return rc;
}
Beispiel #11
0
widget::widget(const variant& v, game_logic::formula_callable* e) 
	: environ_(e), w_(0), h_(0), x_(0), y_(0), zorder_(0), 
	true_x_(0), true_y_(0), disabled_(false), disabled_opacity_(v["disabled_opacity"].as_int(127)),
	tooltip_displayed_(false), id_(v["id"].as_string_default()), align_h_(HALIGN_LEFT), align_v_(VALIGN_TOP),
	tooltip_display_delay_(v["tooltip_delay"].as_int(500)), tooltip_ticks_(INT_MAX),
	resolution_(v["frame_size"].as_int(0)), display_alpha_(v["alpha"].as_int(256)),
	pad_w_(0), pad_h_(0), claim_mouse_events_(v["claim_mouse_events"].as_bool(true)),
	draw_with_object_shader_(v["draw_with_object_shader"].as_bool(true))
{
	set_alpha(display_alpha_ < 0 ? 0 : (display_alpha_ > 256 ? 256 : display_alpha_));
	if(v.has_key("width")) {
		w_ = v["width"].as_int();
	} 
	if(v.has_key("height")) {
		h_ = v["height"].as_int();
	} 
	if(v.has_key("wh")) {
		std::vector<int> iv = v["wh"].as_list_int();
		ASSERT_LOG(iv.size() == 2, "WH attribute must be 2 integer elements.");
		w_ = iv[0];
		h_ = iv[1];
	}
	if(v.has_key("rect")) {
		std::vector<int> r = v["rect"].as_list_int();
		ASSERT_LOG(r.size() == 4, "Four values must be supplied to the rect attribute");
		set_loc(r[0], r[1]);
		set_dim(r[2], r[3]);
	} 
	if(v.has_key("draw_area")) {
		std::vector<int> r = v["draw_area"].as_list_int();
		ASSERT_LOG(r.size() == 4, "Four values must be supplied to the rect attribute");
		set_loc(r[0], r[1]);
		set_dim(r[2], r[3]);
	} 
	if(v.has_key("x")) {
		true_x_ = x_ = v["x"].as_int();
	} 
	if(v.has_key("y")) {
		true_y_ = y_ = v["y"].as_int();
	}
	if(v.has_key("xy")) {
		std::vector<int> iv = v["xy"].as_list_int();
		ASSERT_LOG(iv.size() == 2, "XY attribute must be 2 integer elements.");
		true_x_ = x_ = iv[0];
		true_y_ = y_ = iv[1];
	}
	zorder_ = v["zorder"].as_int(0);
	if(v.has_key("on_process")) {
		on_process_ = boost::bind(&widget::process_delegate, this);
		ffl_on_process_ = get_environment()->create_formula(v["on_process"]);
	}
	if(v.has_key("tooltip")) {
		if(v["tooltip"].is_string()) {
			SDL_Color color = v.has_key("tooltip_color") ? graphics::color(v["tooltip_color"]).as_sdl_color() : graphics::color_yellow();
			set_tooltip(v["tooltip"].as_string(), v["tooltip_size"].as_int(18), color, v["tooltip_font"].as_string_default());
		} else if(v["tooltip"].is_map()) {
			SDL_Color color = v["tooltip"].has_key("color") ? graphics::color(v["tooltip"]["color"]).as_sdl_color() : graphics::color_yellow();
			set_tooltip(v["tooltip"]["text"].as_string(), v["tooltip"]["size"].as_int(18), color, v["tooltip"]["font"].as_string_default());
		} else {
			ASSERT_LOG(false, "Specify the tooltip as a string, e.g. \"tooltip\":\"Text to display on mouseover\", "
				"or a map, e.g. \"tooltip\":{\"text\":\"Text to display.\", \"size\":14}");
		}
	}
	visible_ = v["visible"].as_bool(true);
	if(v.has_key("align_h")) {
		std::string align = v["align_h"].as_string();
		if(align == "left") {
			align_h_ = HALIGN_LEFT;
		} else if(align == "middle" || align == "center" || align == "centre") {
			align_h_ = HALIGN_CENTER;
		} else if(align == "right") {
			align_h_ = HALIGN_RIGHT;
		} else {
			ASSERT_LOG(false, "Invalid align_h attribute given: " << align);
		}
	}
	if(v.has_key("align_v")) {
		std::string align = v["align_v"].as_string();
		if(align == "top") {
			align_v_ = VALIGN_TOP;
		} else if(align == "middle" || align == "center" || align == "centre") {
			align_v_ = VALIGN_CENTER;
		} else if(align == "bottom") {
			align_v_ = VALIGN_BOTTOM;
		} else {
			ASSERT_LOG(false, "Invalid align_v attribute given: " << align);
		}
	}
	disabled_ = !v["enabled"].as_bool(true);
	if(v.has_key("frame")) {
		set_frame_set(v["frame"].as_string());
	}
	if(v.has_key("frame_padding")) {
		ASSERT_LOG(v["frame_padding"].is_list() && v["frame_padding"].num_elements() == 2, "'pad' must be two element list");
		set_padding(v["frame_padding"][0].as_int(), v["frame_padding"][1].as_int());
	} 
	if(v.has_key("frame_pad_width")) {
		set_padding(v["frame_pad_width"].as_int(), get_pad_height());
	}
	if(v.has_key("frame_pad_height")) {
		set_padding(get_pad_width(), v["frame_pad_height"].as_int());
	}
	recalc_loc();
}
Beispiel #12
0
static void
load_items(GltkSpinner* spinner, int level, GList* items)
{
    USING_PRIVATE(spinner);

    Wheel* wheel = priv->wheels + level;

    //clean up an old mess
    if (wheel->items)
    {
        gltk_spinner_model_free_items(priv->model, wheel->items);

        g_object_unref(wheel->vbox);
        wheel->vbox = gltk_vbox_new(0);
        g_object_ref(wheel->vbox);
        gltk_scrollable_set_widget(GLTK_SCROLLABLE(wheel->scrollable), wheel->vbox);
    }

    //make a new one
    wheel->items = items;

    int itemHeight = priv->itemHeight;

    GList* pItems = wheel->items;
    while (pItems)
    {
        GltkSpinnerModelItem* item = (GltkSpinnerModelItem*)pItems->data;

        GltkWidget* label = gltk_label_new(item->text);
        GLTK_LABEL(label)->color.r = 0.0f;
        GLTK_LABEL(label)->color.g = 0.0f;
        GLTK_LABEL(label)->color.b = 0.0f;
        gltk_box_append_widget(GLTK_BOX(wheel->vbox), label, FALSE, FALSE);

        GltkSize size;
        gltk_widget_size_request(label, &size);
        if (size.height > itemHeight)
            itemHeight = size.height;

        size.width = -1;
        size.height = priv->itemHeight;
        gltk_widget_set_size_request(label, size);

        pItems = pItems->next;
    }

    //if our max height changed, relayout and resize
    if (itemHeight > priv->itemHeight)
    {
        priv->itemHeight = itemHeight;

        priv->heightChanged = TRUE;
        gltk_widget_layout(GLTK_WIDGET(spinner));
    }

    //select a specific item
    int len = g_list_length(wheel->items);
    if (wheel->index >= len - 1)
        wheel->index = len-1;
    if (wheel->index < 0)
        wheel->index = 0;
    set_selected_index(spinner, level, wheel->index);

    //set allowable amount to scroll past the vbox
    set_padding(spinner, wheel);

    //either signal that an item was selected or recurse until we do
    if (level == priv->model->levels-1)
    {
        g_object_ref(spinner);
        g_signal_emit(spinner, signals[ITEM_SELECTED], 0);
        g_object_unref(spinner);
    }
    else
    {
        load_items(spinner, level+1, gltk_spinner_model_get_items(priv->model, level, wheel->index));
    }
}
Beispiel #13
0
int s3fs::Crypto::pwriteAES(int fd, const char *buf, size_t buflen, off_t offset)
{
    char readBlock[AES_BLOCK_SIZE];
    unsigned char writeBlock[AES_BLOCK_SIZE];
    unsigned char buffer[AES_BLOCK_SIZE];
    size_t offsetIndex = offset % AES_BLOCK_SIZE;
    size_t readOffset = offset - offsetIndex;
    size_t writeOffset = readOffset;
    size_t bufIndex = 0;
    bool newfile = false;
    int bytesRead = 0;
    int bytesWritten = 0;
    int enclen = 0;
    struct stat st;

    memset(readBlock, 0, AES_BLOCK_SIZE);
    memset(writeBlock, 0, AES_BLOCK_SIZE);
    memset(buffer, 0, AES_BLOCK_SIZE);

    do {
        if(!newfile)
        {
	    if(fstatAES(fd, &st) != 0)
	      return 1;
	  
            bytesRead = preadAES(fd, readBlock, AES_BLOCK_SIZE, readOffset);
            if(bytesRead <= 0)
            {
                newfile = true;
                continue;
            }

            memcpy(buffer, readBlock, bytesRead); //Fill the buffer with contents from the readBlock
            if(bufIndex <= 0)
            {
                memcpy((buffer + offsetIndex), (buf + bufIndex), (AES_BLOCK_SIZE - offsetIndex));
                enclen += (bytesRead + ((buflen - bufIndex) >= AES_BLOCK_SIZE) ? AES_BLOCK_SIZE : (buflen - bufIndex));
		bufIndex += (AES_BLOCK_SIZE - offsetIndex);
            }
            else
            {
                memcpy(buffer, (buf + bufIndex), ((buflen - bufIndex) >= AES_BLOCK_SIZE) ? AES_BLOCK_SIZE : (buflen - bufIndex));
		enclen += ((buflen - bufIndex) >= AES_BLOCK_SIZE) ? AES_BLOCK_SIZE : (buflen - bufIndex);
                bufIndex += ((buflen - bufIndex) >= AES_BLOCK_SIZE) ? AES_BLOCK_SIZE : (buflen - bufIndex);
            }

            //Set padding if needed
            if(enclen < AES_BLOCK_SIZE && ((st.st_size - buflen) < AES_BLOCK_SIZE))
	    {
	      set_padding(buffer, enclen);
	      int padlen = get_padding(buffer);
// 	      FGPRINT("s3fs::Crypto Encrypted padding length %d\n", padlen);
	    }
	    else if (enclen == AES_BLOCK_SIZE && bufIndex == buflen)
	    { 
	      encrypt_block(buffer, AES_BLOCK_SIZE, writeBlock);
	      bytesWritten = pwrite(fd, &writeBlock, AES_BLOCK_SIZE, writeOffset);
	      
	      memset(buffer, 0, AES_BLOCK_SIZE);
	      set_padding(buffer, 0);
	      int padlen = get_padding(buffer);
// 	      FGPRINT("s3fs::Crypto Encrypted padding length %d\n", padlen);
	    }
       
            encrypt_block(buffer, AES_BLOCK_SIZE, writeBlock);
            bytesWritten = pwrite(fd, &writeBlock, AES_BLOCK_SIZE, writeOffset);
            writeOffset += bytesWritten;
            readOffset += bytesRead;
        }
        else
        {
            memset(buffer, 0, AES_BLOCK_SIZE);
            memcpy(buffer, (buf + bufIndex), ((buflen - bufIndex) >= AES_BLOCK_SIZE) ? AES_BLOCK_SIZE : (buflen - bufIndex));
	    enclen += ((buflen - bufIndex) >= AES_BLOCK_SIZE) ? AES_BLOCK_SIZE : (buflen - bufIndex);
	    bufIndex += ((buflen - bufIndex) >= AES_BLOCK_SIZE) ? AES_BLOCK_SIZE : (buflen - bufIndex);

            if(enclen < AES_BLOCK_SIZE)
	    {
	      set_padding(buffer, enclen);
	      int padlen = get_padding(buffer);
// 	      FGPRINT("s3fs::Crypto Encrypted padding length %d\n", padlen);
	    }
	    else if (enclen == AES_BLOCK_SIZE && bufIndex == buflen)
	    { 
	      encrypt_block(buffer, AES_BLOCK_SIZE, writeBlock);
	      bytesWritten = pwrite(fd, &writeBlock, AES_BLOCK_SIZE, writeOffset);
	      writeOffset += bytesWritten;
	      
	      memset(buffer, 0, AES_BLOCK_SIZE);
	      set_padding(buffer, 0);
	      int padlen = get_padding(buffer);
// 	      FGPRINT("s3fs::Crypto Encrypted padding length %d\n", padlen);
	    }

	    encrypt_block(buffer, AES_BLOCK_SIZE, writeBlock);
	    bytesWritten = pwrite(fd, &writeBlock, AES_BLOCK_SIZE, writeOffset);
	    writeOffset += bytesWritten;
        }

        memset(readBlock, 0, AES_BLOCK_SIZE);
        memset(writeBlock, 0, AES_BLOCK_SIZE);
        memset(buffer, 0, AES_BLOCK_SIZE);
	enclen = 0;

    } while(bufIndex < buflen);

    return bufIndex;
}